如何在Maxima CAS中绘制旋转椭圆?
How to draw rotated ellipse in Maxima CAS?
我想画一个以原点为中心的旋转椭圆
我知道how to do it in R and the theory
我的算法:
- 计算由 t
参数化的点列表
- 每个点旋转角度theta
我的代码:
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
)$
结果:
所有椭圆旋转相同的角度。我哪里做错了?
TIA
亚当
公式“y: acos(t)*c + bsin(t)*c”似乎不正确。尝试将其更改为“y: acos(t)*s + bsin(t)*c”,看看是否有效。
在 fang 的帮助下,结果是:
我想画一个以原点为中心的旋转椭圆 我知道how to do it in R and the theory
我的算法:
- 计算由 t 参数化的点列表
- 每个点旋转角度theta
我的代码:
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
)$
结果:
所有椭圆旋转相同的角度。我哪里做错了?
TIA
亚当
公式“y: acos(t)*c + bsin(t)*c”似乎不正确。尝试将其更改为“y: acos(t)*s + bsin(t)*c”,看看是否有效。
在 fang 的帮助下,结果是: