Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Translation of the point normal to the line

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2014

    Translation of the point normal to the line

    I am currently working on a project of drawing thick polylines and I am usin interpolation. I managed to calculate all the necessary points but I need to draw two more points. I need to translate one point normally to the line connecting two points. The scatch below shows what are the points. Naimely point L is to be translated for the distance between L and Jn normally to the line AB (B is the central point). Similar thing is with translation to the Kn.
    I have written the code:

    Code :
            float alpha = atan2(  B.y - A.y,B.x - A.x) - deg90;
            float alpha2 = atan2( C.y - B.y, C.x - B.x) - deg90;
            nJ.x = L.x + w*cos(alpha); // w is distance between A1 and A2
            nJ.y = L.y + w*sin(alpha);
            nK.x = L.x + w*cos(alpha2);
            nK.y = L.y + w*sin(alpha2);

    The code works only for some points, not all. I need to fix + sing in above calculations of nJ and nK, but I do not know how.
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Line1.jpg 
Views:	172 
Size:	10.1 KB 
ID:	1421  

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Think about it this way. There is a component of the point's position that is parallel to the line and a component that is perpendicular. You can use a dot product of the two vectors to isolate the parallel component. Subtract tog get the perpendicular.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts