# How to create hyperbola with C#

**URL:** <https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189>\
**Category:** Rhino Developer\
**Created:** [May 7, 2014, 9:39am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189 "2014-05-07T09:39:52Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![kklu](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kklu](https://discourse.mcneel.com/u/kklu)\
**Post date:** [May 7, 2014, 9:39am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/1 "2014-05-07T09:39:52Z")

</div>

Is there any RhinoCommon function or method to create a hyperbola curve?

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [May 7, 2014, 10:14am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/2 "2014-05-07T10:14:47Z")

</div>

Hyperbolae are part of the family of curves called conic sections. These also include ellipses and circles. Conic sections are rational quadratic NURBS curves. As Rhino uses NURBS curves, it is possible to represent a hyperbola as a NURBS curve.

Now, how to get from a formula of a hyperbola to a NURBS representation of the conic section, I can’t tell you. There is much information available on the web though.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [May 7, 2014, 5:11pm UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/3 "2014-05-07T17:11:18Z")

</div>

Hi KK,

No, there is no method in RhinoCommon to create a hyperbola. What input would you expect to provide in order to produce one?

---

<div class="post-metadata">

**Author:** ![defterGoose](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/deftergoose/32/285754_2.png) [@defterGoose](https://discourse.mcneel.com/u/defterGoose)\
**Post date:** [May 7, 2014, 6:46pm UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/4 "2014-05-07T18:46:06Z")

</div>

If you’re just looking to get the general shape for reference (and not an infinitely extending functional curve, which isnot practically possible in modeling software), you could do as menno implied and take a section yourself. Cones are available as primitives so do the following:

-make a cone  
-mirror the cone about its tip  
-draw a plane parallel to the conic axis  
-intersect the plane and the two cones

---

<div class="post-metadata">

**Author:** ![kklu](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kklu](https://discourse.mcneel.com/u/kklu)\
**Post date:** [May 8, 2014, 2:02am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/5 "2014-05-08T02:02:33Z")

</div>

Hi Dale,

```
  I shall input the vertex, focus and hyperbola end for a hyperbola calculation as the 'Hyperbloa' command.
```

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [May 8, 2014, 6:05am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/6 "2014-05-08T06:05:26Z")

</div>

Maybe the`Conic`command in Rhino is what you are looking for?

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [May 8, 2014, 6:54am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/7 "2014-05-08T06:54:34Z")

</div>

There is even a `Hyperbola` command in Rhino. You could use `RhinoApp.RunScript` to make a hyperbola.

---

<div class="post-metadata">

**Author:** ![kklu](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kklu](https://discourse.mcneel.com/u/kklu)\
**Post date:** [May 8, 2014, 7:41am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/8 "2014-05-08T07:41:51Z")

</div>

Hi Menno,  
It is true that there is a Rhino command to create a hyperbola. On my case, I need to build a C# function which request user to pick a point constrained on a temporary hyperbola locus. So, I cannot use RhinoApp.RunScript for this purpose.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/770384_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [May 8, 2014, 8:24am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/9 "2014-05-08T08:24:47Z")

</div>

It is possible to write a hyperbola as a quadratic Bezier curve. There is a paper that outlines this in detail, but unfortunately the formulae in the paper are a bit broken, some symbols do not show correctly. But maybe it is enough to point you in the right direction.

> **[77.pdf](https://www.improve2011.it/Full_Paper/77.pdf)**
>
> 542.41 KB

---

<div class="post-metadata">

**Author:** ![kklu](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kklu](https://discourse.mcneel.com/u/kklu)\
**Post date:** [May 8, 2014, 9:03am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/10 "2014-05-08T09:03:42Z")

</div>

Menno, thank for your help.

---

<div class="post-metadata">

**Author:** ![danieldavis](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@danieldavis](https://discourse.mcneel.com/u/danieldavis)\
**Post date:** [May 10, 2014, 11:44pm UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/11 "2014-05-10T23:44:10Z")

</div>

Lots of my work involves hyperbolas and hyperboloids. Here is my hyperbola code in Python with some explanation of what is going on. This will draw a symmetrical hyperbola on the XZ plane, centred at 0,0,0.

```
# A hyperbola can be drawn as a quadratic rational bezier curve
# The curve has three control points: p0, p1, p2
# p0 & 02 are the end points of the curve
# p1 is near the apex of the curve
#
# Since the hyperboloid is being generated about the z-axis, we can assume
# p0 & p2 are mirror images of one another about the xy plane.
# p0 & p2 can be calculated directly from the hyperbola formula:
# x^2 / a^2 - y^2 / b^2 = 1
# In this case, because we are drawing vertically, y = z = height of the hyperbola
# so a, b, and z are known. Thus:
# x^2 = a^2 * (1 + (z^2 / b^2)) 

a = 1
b = 1
height = 10 
x = math.sqrt(a*a * (1 + ((height*height) / (b * b))))
p0 = Rhino.Geometry.Point3d(x,0, height)
p2 = Rhino.Geometry.Point3d(x,0 ,-1 * height)

# p1 is harder to calculate.
# It lies on the x-axis, at the intersection of the tangents from p0 & 02
# The tangent for a point(x', y') on a hyperbola is:
# y-y' = (b^2 * x') / (a^2 * y') * (x - x')
# http://openstudy.com/updates/4f7ef8c8e4b0bfe8930b75a2
# Since we know y = 0, we can solve for x
# x = (-y'^2 * a^2) / (b^2 * x') + x'
# where x' and y' are the point on the hyperbola 

x = (-1 * p0.Z * p0.Z * a * a) / (b * b * p0.X) + p0.X
p1 = Rhino.Geometry.Point3d(x,0,0)

# We also need the apex point for the hyperbola
# This is the point where the hyperbola crosses the x-axis
 
apex = Rhino.Geometry.Point3d(a,0,0)

# To draw the hyperbola, we need to know what weight is given to p1
# The formula is:
# d = weight / (1 + weight) * e
# http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/NURBS/RB-conics.html
# where d = the distance between the apex and point_M
# and e = the distance between p1 and point_M
# and point_M is midway between p0 and p2
# thus, the weight = d / (e - d) 

point_M = p0.X
d = point_M - apex.X
e = point_M - p1.X

weight = d / (e - d)

# create hyperbola
points = [p0, p1, p2]
hyperbola = Rhino.Geometry.NurbsCurve.Create(False, 2, points) 
hyperbola.Points.SetPoint(1, Rhino.Geometry.Point4d(p1.X, p1.Y, p1.Z, weight))

```

---

<div class="post-metadata">

**Author:** ![kklu](https://avatars.discourse-cdn.com/v4/letter/k/cdc98d/32.png) [@kklu](https://discourse.mcneel.com/u/kklu)\
**Post date:** [May 12, 2014, 12:59am UTC](https://discourse.mcneel.com/t/how-to-create-hyperbola-with-c/8189/12 "2014-05-12T00:59:18Z")

</div>

Hi Danieldavis,

```
  Many thanks to your help. Your guide is useful to solve my problem.
```
