Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: rotating lines in 2d space

  1. #1
    Intern Newbie
    Join Date
    Jun 2001
    Posts
    35

    rotating lines in 2d space

    Hi,

    I'm struggeling with with a problem and culd use some help.

    I have 2 lines somewhere in 2D space. One line is described by two known points p1, p2.
    The other line is described by the unknown points p3, p4, but with a known length.
    Now I need to connect p3 of the second line to either p1 or p2. The direction/alignment of the second line is defined by a known angle between the first line.
    My problem now is to determine the second point p4 of the second line, given by p1, p2, p3 connected with either p1 or p2 and the angle between those lines.
    I guess I have to apply some sort of rotation but I can't figure out how.

    Any ideas?

    Thanks in advance for any help!

  2. #2
    Intern Contributor
    Join Date
    Sep 2003
    Location
    Jersey, Channel Islands
    Posts
    68

    Re: rotating lines in 2d space

    By lines, do you actually mean line segments here? If yes:

    You know P1 and P2. You don't know P3 and P4 but you know distance(P3,P4). Also you know the angle between the two line segments. Puttin all this together, you end up with any two point on a line, whose distance is the dist(P3,P4) and this line is at a certain angle with line(P1,P2).

    The description above gives you an infinite number of possible line(P3,P4) and for each one of these line, an infinite number of P3,P4 pairs.

    If you connect P3 with , say, P1, that places the line(P3,P4) on a cone, the apex of which is P1(and P3), and the acis is the line(P1,P2). In order to actually place P4, you need a second angle, around the line(P1,P2) axis.

    madmortigan

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    11

    Re: rotating lines in 2d space

    p1, p2, p3, and p4 have x and y components, defined by p#x and p#y.

    r is the length from p3 to p4

    t is the angle between the two lines
    p3 = //p1 or p2, however you want to define that
    if(p3==p1){
    dx = p2x-p1x;
    dy = p2y-p1y;
    }
    else{
    dx = p1x-p2x;
    dy = p1y-p2y;
    }
    nx = p1x/sqrt(dx*dx + dy*dy);
    ny = p1y/sqrt(dx*dx + dy*dy);

    p4x = p3x + nx *(r * cos(t));
    p4y = p3x + nx *(r * sin(t));
    capn_midnight | Captain Midnight | deviantArt
    ACM | SIGGRAPH | Generation5

Posting Permissions

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