我在尝试用方程的偏移量 C 绘制极地玫瑰时遇到了一些麻烦
r(theta) = cos(k*theta) + C。
我正在尝试绘制这朵极地玫瑰:
http://en.wikipedia.org/wiki/Polar_coordinate_system#/media/File:Cartesian_to_polar.gif
极坐标方程可以是:
r(theta) = cos(k * theta)
或
r(theta) = sin(k * theta)
我要画的极地玫瑰的方程是:
r(θ) = 2 + sin(6 * θ)
好的,参数方程将是:
x = C + sin(k * theta) * cos(theta)
y = C + sin(k * theta) * sin(theta)
在我的 Canvas(绘图区域)中,我的原点不在屏幕中心,所以我需要将玫瑰平移到它。好的,没什么大不了的。另一点是我需要缩放玫瑰以使其可见,否则它会太小,但仍然没问题,这解释了:100*。这是我的代码,它是在 C++ 上顺便说一句:
for ( float t = 0; t < PI_2; t+= 0.01 )
{
r = Origin.get_x() + 100*(2+(sin(6*t) * cos(t)));
h = Origin.get_y() + 100*(2+(sin(6*t) * sin(t)));
point(r,h);
}
我知道我做错了,因为当我添加应该是 C 常数的 +2 时,它没有按照我想要的方式工作,它只是翻译更多并绘制没有偏移的极地玫瑰。如何防止“额外翻译”并正确绘制?
最佳答案
x = r cos(theta)
, y = r sin(theta)
所以你的参数方程应该是 x(theta) = C * cos( theta) + sin(k*theta) * cos(theta)
和 y(theta) = C * sin(theta) + sin(k*theta) * sin(theta)
。您只是忘记了将 C
分别乘以 cos(theta)
和 sin(theta)
。
关于c++ - 极地玫瑰 2D 偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29586140/