Family of curves y=x, y=x^2, y=x^3, …, y=x^n

putting the curve drawing loop inside another loop.

Sub testparabola3()
Call connect_acad
Call parabola3(-2, 2, 3, 0.1)
End Sub

Sub parabola3(min_x As Double, max_x As Double, n2 As Integer, x_inc As Double)
'y = x^n
Dim x As Double, y As Double
Dim i As Integer, n As Integer
Dim plineobj As AcadLWPolyline
Dim pt() As Double
Dim 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 n = 1 To n2

For i = 1 To numpts
x = min_x + ((i - 1) * x_inc)
'when i = 1 then x = min_x
y = x ^ n
pt(i * 2 - 1) = x: pt(i * 2) = y
'for each numpts there is an x and y pt(index)
Next i

Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt)
Next n

End Sub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s