我想绘制正弦曲线上的移动点并绘制曲线上该点的切线和法线。我也想规范这些线,但这不是我主要关心的问题。OpenGL - 画正切和正弦曲线
到目前为止,我认为我的切线是好的,但我找不到如何画正常。
这是我到目前为止有: 两个定义,以避免在代码
#define SIN(A, y, x) A * sin(((2 * M_PI)/y) * x)
#define COSDY(A, y, x) A * ((2 * M_PI)/y) * cos(((2 * M_PI)/y) * x)
中间键入而这些都是我的曲线,切线,然后正常做图中:
glBegin(GL_LINE_STRIP);
for (x = -1.f; x <= 1.f; x += 0.01) {
glVertex3f(x, SIN(1, 2, x), 1.f);
}
glEnd();
glPointSize(10.0);
glBegin(GL_POINTS);
glVertex3f(position, SIN(1, 2, position), 1.f);
glEnd();
glPointSize(1.0);
float dx = 1;
float dy = COSDY(1, 2, position);
float mag = sqrtf(dx * dx + dy * dy);
dx /= mag;
dy /= mag;
glBegin(GL_LINES);
glVertex3f(position, SIN(1, 2, position), 1.f);
glVertex3f(position + dx, position + dy, 1.f);
glEnd();
glBegin(GL_LINES);
glVertex3f(position, SIN(1, 2, position), 1.f);
glVertex3f(position + dy, position - 1/dx, 1.f);
glEnd();
正如我所说的切线看起来不错,但正常是绝对不行。
你可以看到什么是问题呢?
您可以添加坏法线的屏幕截图吗? –