c - OpenGL - Draw tangent and normal to sine curve -


i trying draw moving point on sine curve , draw tangent , normal point on curve. normalize these lines, not main concern.

so far think tangent can't find how draw normal.

here have far : 2 defines avoid typing in middle of code

#define sin(a, y, x) * sin(((2 * m_pi) / y) * x) #define cosdy(a, y, x) * ((2 * m_pi) / y) * cos(((2 * m_pi) / y) * x) 

and drawings curve, tangent , normal:

glbegin(gl_line_strip);  (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(); 

as said tangent looks ok normal not ok.

bad normals

can see problem in this?

the calculation of tangent looks ok. don't quite understand way draw it, though. if (dx, dy) tangent vector, shouldn't drawing code this?

glvertex3f(position, sin(1, 2, position), 1.f); glvertex3f(position + dx, sin(1, 2, position) + dy, 1.f); 

in case, (dx, dy) being tangent vector, 2 options normal vector (dy, -dx) , (-dy, dx). remember scalar product of 2 vectors needs 0 2 vectors orthogonal. normal drawing becomes:

glvertex3f(position, sin(1, 2, position), 1.f); glvertex3f(position + dy, sin(1, 2, position) - dx, 1.f); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -