c++ - Circular Arc Through a Center Point -



c++ - Circular Arc Through a Center Point -

i'm attempting render arc through 3 specified points in opengl. far i've managed compute of different values required (center , radius of circle passing through 3 points, , start , end angle). problem comes deciding on direction draw arc, clockwise or counter-clockwise, dependent on location of middle point. code follows: (hacky experimental code, points[0] start, points[1] middle , points[2] end)

void render() { glclear(gl_color_buffer_bit | gl_depth_buffer_bit); glcolor3f(0.0f, 0.0f, 0.0f); // circle parameters point2d center = circlecenter(points[0], points[1], points[2]); double circleradius = radius(points[0], points[1], points[2]); // arc parameters double start = atan2(points[0].y - center.y, points[0].x - center.x) * (180 / m_pi); double middle = atan2(points[1].y - center.y, points[1].x - center.x) * (180 / m_pi); double end = atan2(points[2].y - center.y, points[2].x - center.x) * (180 / m_pi); if (start < 0) start += 360; if (middle < 0) middle += 360; if (end < 0) end += 360; // render circle glbegin(gl_line_strip); (int = start; < end; i++) { double deginrad = * m_pi / 180; glvertex2d(cos(deginrad)*circleradius + center.x, sin(deginrad)*circleradius + center.y); } glend(); glutswapbuffers(); }

as can see arc beingness rendered between start , end points. need in order ensure renders in right direction, through center point?

update 1: example, in below diagrams bluish points 3 defined points , reddish circle center. in top image, arc passes through middle point. in bottom image, arc still draw clockwise though middle point on right. same occurs different start/end point combinations. there uniform way ensure arc passes through center point?

right:

wrong:

you can check middle lies.

(...) if (end < start) end += 360; if (middle < start) middle += 360; if (middle < end) donormal = true; else donormal = false; // render circle glbegin(gl_line_strip); (int = donormal ? start : end; < donormal ? end : start; += donormal ? 1 : -1) (...)

c++ opengl geometry circle

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -