' Ellipse Drawing Script
' The following code will draw an ellipse using Construction Slice lines
'
' Equation of an ellipse: ((x-h)^2)/a^2 + ((y-k)^2)/b^2 = 1
' where
' (h,k) is the center of the ellipse
' a is the semi-major axis length
' b is the semi-minor axis length
'
' Parametric equation is used here
' x=h+a*cos(t)*cos(theta)-b*sin(t)*sin(theta)
' y=k+b*sin(t)*cos(theta)+a*cos(t)*sin(theta)
' where
' t is the parameter
' theta=angle of rotation about center, with respect to x-axis
' Constants
h=5 'x-coordinate of center of ellipse
k=7 'y-coordinate of center of ellipse
a=15 'Semi-major axis length
b=8 'Semi-minor axis length
theta=0 'Angle of Rotation (degrees)
nblines=50 'Number of lines to be used in discretization
PI=3.14159265358979323846
'Initialization of parameter
t=0
'Starting point calculation
x1=h+a*cos(t*PI/180)*cos(theta*PI/180)-b*sin(t*PI/180)*sin(theta*PI/180)
y1=k+b*sin(t*PI/180)*cos(theta*PI/180)+a*cos(t*PI/180)*sin(theta*PI/180)
For i = 1 to nblines
t=t+(360/nblines) 't is incremented by 360/nblines for each iteration
'End point calculation
x2=h+a*cos(t*PI/180)*cos(theta*PI/180)-b*sin(t*PI/180)*sin(theta*PI/180)
y2=k+b*sin(t*PI/180)*cos(theta*PI/180)+a*cos(t*PI/180)*sin(theta*PI/180)
Call getDocument().getView().newLine(x1,y1, x2, y2)
x1=x2
y1=y2
Next 楼上牛人,膜拜ing~ 多谢楼主分享,学习了。
页:
1
[2]