# Hyperbola

We are at the point now where we can create a new program using the parabola polyline as template just by pasting in a single equation into the loop, and watching that the input list provides the correct variables.

```Sub testhyperbola()
Call connect_acad
Call hyperbola(-5, 5, 5, 4, 0.1)
End Sub

Sub hyperbola(min_x As Double, max_x As Double, a As Double, b As Double, x_inc As Double)
'y=  (((x^2) * (a^2) / (b^2)) + a^2)^(1/2)
Dim x As Double, y As Double
Dim plineobj As AcadLWPolyline
Dim pt() As Double
Dim i As Integer, numpts As Integer

numpts = (max_x - min_x) / x_inc 'this is the number of line segments
numpts = numpts + 1  'there is always one more pt than line segment
ReDim pt(1 To numpts * 2) 'to store both x and y for one pt

For i = 1 To numpts
x = min_x + ((i - 1) * x_inc)
y = (((x ^ 2) * (a ^ 2) / (b ^ 2)) + a ^ 2) ^ (1 / 2)
pt(i * 2 - 1) = x: pt(i * 2) = y
Next i

Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt)
ZoomAll
End Sub
```

This only creates one side of one type of hyperbola, so the quickest brute force way to create the negative version on the other side of the axis is to re-run the loop with a negative sign on the equation.

```Sub hyperbola(min_x As Double, max_x As Double, a As Double, b As Double, x_inc As Double)
'y=  (((x^2) * (a^2) / (b^2)) + a^2)^(1/2)
Dim x As Double, y As Double
Dim plineobj As AcadLWPolyline
Dim pt() As Double
Dim i As Integer, numpts As Integer

numpts = (max_x - min_x) / x_inc 'this is the number of line segments
numpts = numpts + 1  'there is always one more pt than line segment
ReDim pt(1 To numpts * 2) 'to store both x and y for one pt

For i = 1 To numpts
x = min_x + ((i - 1) * x_inc)
y = (((x ^ 2) * (a ^ 2) / (b ^ 2)) + a ^ 2) ^ (1 / 2)
pt(i * 2 - 1) = x: pt(i * 2) = y
Next i
Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt)

For i = 1 To numpts
x = min_x + ((i - 1) * x_inc)
y = -(((x ^ 2) * (a ^ 2) / (b ^ 2)) + a ^ 2) ^ (1 / 2)
pt(i * 2 - 1) = x: pt(i * 2) = y
Next i
Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt)

ZoomAll
End Sub
```
Advertisements

This site uses Akismet to reduce spam. Learn how your comment data is processed.