Ellipse

The ellipse is a little different but not much.

Now that we have a small basic stable of routines, we will turn to making an xy axes and then a userform to run the procedures.

Sub testellipse()
Call connect_acad
Call ellipse(16, 8, 0.1)
End Sub

Sub ellipse(a As Double, b As Double, t_inc As Double)
'x = a * Cos(t)
't = b * Sin(t)
'where 0<t<6.283 which is 2 pi

Dim x As Double, y As Double, t As Double
Dim plineobj As AcadLWPolyline
Dim pt() As Double
Dim i As Integer, numpts As Integer
Dim max_t As Double
max_t = 2 * 3.14159265359

numpts = (max_t) / t_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
t = 0 + (i - 1) * t_inc
x = a * Cos(t)
y = b * Sin(t)
pt(i * 2 - 1) = x: pt(i * 2) = y
Next i
Set plineobj = acadApp.ActiveDocument.ModelSpace.AddLightWeightPolyline(pt)

End Sub
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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