## fbcadcam macro to plot a rotated ellipse

Community contributed macros

Moderators: yajra1219, Jayem, kitty_webb, Ywsp, joanCruz03, shela

owen
Posts: 654
Joined: Thu Apr 13, 2017 12:14 pm

### fbcadcam macro to plot a rotated ellipse

Code: Select all

``````Dim As Double pi
Dim As Double d2r
Dim As Double r2d

Dim As Double cx,cy,x1,y1,x2,y2
Dim As Double major_r,minor_r
Dim As Double rotation,rotation_r
Dim As Double pt_angle
Dim As Integer i
pi = 4 * Atn(1)
d2r = pi/180
r2d = 180/pi

cx=200'ellipse center X
cy=200'center Y
rotation=45'ellipse roation in degrees

'draw everything rotated

'calculate x1,y1 at 0 derees (unrotated)
x1=cx+Cos(d2r*0)*major_r
y1=cy+Sin(d2r*0)*minor_r
rotation_r=Sqr((cx-x1)^2+(cy-y1)^2)
'rotate x1,y1 which is at zero degrees + the ellipse rotation
x1=cx+Cos(d2r*(0+rotation))*rotation_r
y1=cy+Sin(d2r*(0+rotation))*rotation_r

'so now we calcualte the remaing points thru 360 degrees
For i = 1 To 360
'calculate x1,y1 at i derees (unrotated)
x2=cx+Cos(d2r*i)*major_r
y2=cy+Sin(d2r*i)*minor_r
'PSet(x2,y2),14
rotation_r=Sqr((cx-x2)^2+(cy-y2)^2)
'calculate the angle of that point
pt_angle=r2d*ATan2((y2-cy),(x2-cx))
pt_angle+=rotation
'rotate x2,y2
x2=cx+Cos(d2r*(pt_angle))*rotation_r
y2=cy+Sin(d2r*(pt_angle))*rotation_r
Line(x1,y1)-(x2,y2)
x1=x2
y1=y2
Next

``````

owen
Posts: 654
Joined: Thu Apr 13, 2017 12:14 pm

### Re: fbcadcam macro to plot a rotated ellipse

Code: Select all

``````Dim As Double focilength,majr,minr
majr=200
minr=100

ScreenRes 600,600
Window(0,0)-(599,599)
Dim As Double foci,f1x,f1y'foci(length),foci#1 left side
Dim As Double f2x,f2y'foci#2 right side
Dim As Integer er1,er2'major and minor radius
Dim As Integer ex,ey'ellipse center
Dim As Double ptx,pty
ex=300
ey=300
er1=200
er2=150
foci=Sqr(Abs(er1^2-er2^2))
f1x=ex-foci
f1y=ey
f2x=ex+foci
f2y=ey
Circle(ex,ey),10,14'just to show u the center of ellipse
Circle(f1x,f1y),10,13'show the left foci#1
Circle(f2x,f2y),10,12'show the right foci#2

'now lets plot 360 points on the circumference of ellipse
For degrees As Integer=0 To 359
ptx=ex+Cos(degrees*3.14/180)*er1
pty=ey+Sin(degrees*3.14/180)*er2
pset(ptx,pty),14'just drawing some small points at these points
'so you can see the outline of an ellipse
Next
Sleep

``````

owen
Posts: 654
Joined: Thu Apr 13, 2017 12:14 pm

### Re: fbcadcam macro to plot a rotated ellipse

Code: Select all

``````

ScreenRes 600,600
Window(0,0)-(599,599)
Dim As Double pi,r2d,d2r
pi = 4 * Atn(1)
d2r = pi/180
r2d = 180/pi
Dim As Double foci,f1x,f1y'foci(length),foci#1 left side
Dim As Double f2x,f2y'foci#2 right side
Dim As Integer er1,er2'major and minor radius
Dim As Integer ex,ey'ellipse center
Dim As Double ptx,pty'point on ellipse
Dim As Double optx,opty'offset point (or parallel point)
Dim As Double afpoe2f1'angle from point on ellpse to foci#1
Dim As Double afpoe2f2'angle from point on ellpse to foci#2
Dim As Double normal'the bisector for outward offset
Dim As Integer dbr'drill bit radius
dbr=20
ex=300
ey=300
er1=200
er2=150
foci=Sqr(Abs(er1^2-er2^2))
f1x=ex-foci
f1y=ey
f2x=ex+foci
f2y=ey

Circle(ex,ey),10,14'just to show u the center of ellipse
Circle(f1x,f1y),10,13'show the left foci#1
Circle(f2x,f2y),10,12'show the right foci#2

'now lets plot 360 points on the circumference of ellipse
For degrees As Integer=0 To 359
ptx=ex+Cos(degrees*d2r)*er1
pty=ey+Sin(degrees*d2r)*er2
PSet(ptx,pty),14'just drawing some small points at these points
'so you can see the outline of an ellipse
'now let's calc the angle of the bisector
'as we itterate thru all 360 points
'first let's calc the angle from point on ellipse to foci#1
afpoe2f1=r2d*ATan2((f1y-pty),(f1x-ptx))
afpoe2f2=r2d*ATan2((f2y-pty),(f2x-ptx))
If afpoe2f1<0 Then afpoe2f1+=360
If afpoe2f2<0 Then afpoe2f2+=360
'Print afpoe2f1,afpoe2f2
'Sleep
normal=afpoe2f1+abs(afpoe2f1-afpoe2f2)/2+180
'now draw a line from point on ellipse at (the angle of) normal at length drill bit radius
'remember this is nothing more complicated the plotting a point on a circle
optx=ptx+Cos(normal*d2r)*dbr
opty=pty+Sin(normal*d2r)*dbr
Line(ptx,pty)-(optx,opty)
sleep
Next
Sleep

``````