c++ - 极地玫瑰 2D 偏移

标签 c++ 2d polar-coordinates parametric-equations

我在尝试用方程的偏移量 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/

相关文章:

c - 如何栅格化旋转的矩形(通过 setpixel 在 2d 中)

python - 如何在 matplotlib 中的极轴上使用对数刻度

python - 如何使用 matplotlib 在极坐标图中绘制曲线/圆弧?

c++ - GTK+ g_pointer_connect 错误地传递数据

c++ - 像 union_ 这样的 Boost.Geometry 操作如何处理浮点类型的基本不精确性?

c++ - 1 字节共享内存是否需要 Mutex

javascript - 如何使用两个坐标用javascript画一个椭圆?

c++ - 第二个对话框上的C++ MFC按钮不起作用

java - OpenGL:2D 叠加在 3D 场景上是白色的

gnuplot - 如何将 gnuplot polar 限制在 180 度范围内?