【发布时间】:2015-06-24 20:46:55
【问题描述】:
画四叶玫瑰真的很麻烦:这是练习:
画出“四叶玫瑰”,其极坐标方程为 r =cos(2θ) 。让 θ 以 100 步从 0 变为 2*pi。每次计算 r,然后使用公式从极坐标计算 (x, y) 坐标 x = r ⋅ cos( θ ) , y = r ⋅ sin(θ )
我的代码:
public Rose(double awidth, double aheight)
{
width = awidth;
height = aheight;
theta = 0;
}
public void drawRose(Graphics2D g2)
{
Ellipse2D.Double test ;
double r = 0;
for(int i = 0; i <= 100; i++)
{
r = Math.cos(Math.toRadians(2*theta) );
x = r *( Math.cos( Math.toRadians(theta) ) * width ) + 300;
y = r * ( Math.sin( Math.toRadians(theta) ) * height ) + 300 ;
test = new Ellipse2D.Double(x, y, width, height);
theta += 3.6;
g2.draw(test);
}
}
}
任何帮助将不胜感激。
【问题讨论】:
-
您的实施到底有什么问题?
-
我自己,我不会创建 Ellipse2D 对象,而是使用公式创建
List<Point>,然后在列表中的点之间画线。 -
我还没有了解List
。 -
@MarsAtomic,它不会画出四叶玫瑰