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

# How to create hyperbola with C#

**menno**(Menno Deij - van Rijswijk) #2

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.

**dale**(Dale Fugier) #3

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?

**defterGoose**#4

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

**kklu**#5

Hi Dale,

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

**menno**(Menno Deij - van Rijswijk) #7

There is even a `Hyperbola`

command in Rhino. You could use `RhinoApp.RunScript`

to make a hyperbola.

**kklu**#8

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.

**menno**(Menno Deij - van Rijswijk) #9

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.

**danieldavis**#11

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))
```