I would like to draw rotated ellipse, centered at origin I know how to do it in R and the theory
My algorithm:
My code:
deg2rad(t):= float(t*2*%pi/360)$
GiveRotatedEllipse(a,b,theta, NumberOfPoints):=block(
[x, y, zz, t , tmin, tmax, dt, c, s],
zz:[],
dt : 1/NumberOfPoints,
tmin: 0,
tmax: 2*%pi,
c:float(cos(theta)),
s:float(sin(theta)),
for t:tmin thru tmax step dt do(
x: a*cos(t)*c - b*sin(t)*s,
x: float(x),
y: a*cos(t)*c + b*sin(t)*c,
y:float(y),
zz: cons([x,y],zz)
),
return (points(zz))
)$
/* compute */
/* angles fo trigonometric functions in radians */
angle_step :deg2rad(15) $ /* 2*%pi/3$ */
radius_x: 3$
radius_y: 2$
e0:GiveRotatedEllipse(radius_x, radius_y, 0, 100)$
e1: GiveRotatedEllipse(radius_x, radius_y, angle_step, 100)$
e2: GiveRotatedEllipse(radius_x, radius_y, 2*angle_step, 100)$
path:""$
load(draw);
draw2d(
user_preamble="set key top right; unset mouse",
terminal = 'png,
file_name = sconcat(path,"e"),
dimensions = [1000, 1000],
proportional_axes = xy,
line_width = 2,
line_type = solid,
fill_color = white,
point_type=filled_circle,
point_size = 0.5,
key = "e0",
color = red,
e0,
key= "e1",
color=blue,
e1,
key= "e2",
color= green,
e2
)$
All ellipses are rotated by the same angle. Where I did a mistake?
TIA
Adam
The formula "y: acos(t)*c + bsin(t)*c" does not seem to be correct. Try changing it to "y: acos(t)*s + bsin(t)*c" to see if it works.