连接极坐标图坐标
Connecting Polar Graph Coordinates
我的程序是极坐标绘图window。我的问题是,当我绘制 r=a*sin(b*theta)
图表时。下面显示的我的具体示例使用 a=12
和 b=8
。当我将绘制的点连接到下一个点时,我会在下面显示一些内容:
线条好像画在花瓣上,看起来很美妙,但不正确。下面是绘制点和线的代码:
for(int i=0; i< ptr.size(); i++){
drawPoint(g2d, ptr.get(i), ptt.get(i));
if(connectPoints && i!=ptr.size()-1){
g.drawLine((int)(origin_x+Math.cos(ptt.get(i))*ptr.get(i)*ppp),
(int)(origin_y-Math.sin(ptt.get(i))*ptr.get(i)*ppp),
(int)(origin_x+Math.cos(ptt.get(i+1))*ptr.get(i+1)*ppp),
(int)(origin_y-Math.sin(ptt.get(i+1))*ptr.get(i+1)*ppp));
}
}
ptr
包含 r 值,ptt
包含 theta 值。这是添加点的行:
for(double i=0; i<100; i+=0.1){
pg.plot(12*Math.cos(8*i), i);
}
为什么会这样?如何修复?提前致谢!
您不止一次遍历圆圈,每次遍历的样本点都不相同。这就是为什么你的线条会穿过花瓣。尝试:
double numberOfSteps = 1000;
double stepSize = 2.0 * Math.PI / numberOfSteps;
for(double i=0; i<numberOfSteps; i++){
double theta = i * stepsize;
pg.plot(12*Math.cos(8.0 * theta), theta);
}
尝试 numberOfSteps
进行微调。
我的程序是极坐标绘图window。我的问题是,当我绘制 r=a*sin(b*theta)
图表时。下面显示的我的具体示例使用 a=12
和 b=8
。当我将绘制的点连接到下一个点时,我会在下面显示一些内容:
线条好像画在花瓣上,看起来很美妙,但不正确。下面是绘制点和线的代码:
for(int i=0; i< ptr.size(); i++){
drawPoint(g2d, ptr.get(i), ptt.get(i));
if(connectPoints && i!=ptr.size()-1){
g.drawLine((int)(origin_x+Math.cos(ptt.get(i))*ptr.get(i)*ppp),
(int)(origin_y-Math.sin(ptt.get(i))*ptr.get(i)*ppp),
(int)(origin_x+Math.cos(ptt.get(i+1))*ptr.get(i+1)*ppp),
(int)(origin_y-Math.sin(ptt.get(i+1))*ptr.get(i+1)*ppp));
}
}
ptr
包含 r 值,ptt
包含 theta 值。这是添加点的行:
for(double i=0; i<100; i+=0.1){
pg.plot(12*Math.cos(8*i), i);
}
为什么会这样?如何修复?提前致谢!
您不止一次遍历圆圈,每次遍历的样本点都不相同。这就是为什么你的线条会穿过花瓣。尝试:
double numberOfSteps = 1000;
double stepSize = 2.0 * Math.PI / numberOfSteps;
for(double i=0; i<numberOfSteps; i++){
double theta = i * stepsize;
pg.plot(12*Math.cos(8.0 * theta), theta);
}
尝试 numberOfSteps
进行微调。