Results 1 to 3 of 3

Thread: dumb vector math question---point on a line

  1. #1

    dumb vector math question---point on a line

    Hi--

    so I have my 3d line equation of the form:

    P = P1 + k(P2-P1) where Pn is <x, y, z>.

    A line can be defined just through the points P1, P2, so how do I solve for k and P in the equation?

    Forget the point-in-line test for the moment. Given a known P1, P2, what do I set P equal to to solve for k? can P just be equal to P1 or P2? If this is the case, don't i get different results for k depending on whether or not P = P1 or P2?

    Like, if we have P = P1 + k(P2-P1),
    can I then say P1 = P1 +k(P2-P1)?
    rearranging, that seems like it just becomes P1 - P1/(P2-P1) = k = 0.

    alternatively, if i put P = P2, i get the equation P2 = P1 + k(P2-P1), which is equal to (P2-P1)/(P2-P1) = k = 1.

    So given that I can define my line with _only_ P1 and P2, what value should i substitute for P to solve for K?

    Thanks a lot


    Max

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2011
    Posts
    288

    Re: dumb vector math question---point on a line

    In most cases, you want to find k, such that the P on the line is closest to the P' you input. A tolerance can be used to determine whether the point is on the line.
    Try searching thru google by keywords:
    "Point line distance"

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: dumb vector math question---point on a line

    Let's look at the equation:

    P = point on the line(x,y,z)
    k = is a number between 0 and 1, 0.5 being midpoint on the line.

    If k = 0, then P = P1
    If k = 1, then P = p2
    If k = 0.5 then P = P1 + 0.5 * (P2 - P1) which translates to this in C code:

    P.x = P1.x + 0.5 * (P2.x - P1.x);
    P.y = P1.y + 0.5 * (P2.y - P1.y);
    P.z = P1.z + 0.5 * (P2.z - P1.z);

    I don't see the need to find k, but here is what would be the answer.

    We need only solve for one axis:

    k = (P.x - P1.x)/(P2.x - P1.x)

    Normally we use k for movement between two points on our vector.

    ship starts at vector P1 and will end at P2.

    k = 0 ship starting point.
    k = 1 ship ending point.

    k = 0;

    loop_start

    k +=0.01; Rate of movement.

    P = P1 + k * ( P2 -P1 );

    draw_ship_at( P );

    keep looping until k = 1 ending point.

    Originally posted by Coconut:
    In most cases, you want to find k, such that the P on the line is closest to the P' you input. A tolerance can be used to determine whether the point is on the line.
    Try searching thru google by keywords:
    "Point line distance"



    [This message has been edited by nexusone (edited 11-14-2002).]

Similar Threads

  1. Replies: 3
    Last Post: 10-06-2017, 06:35 AM
  2. point perpendicular to a vector question
    By brett01 in forum OpenGL: General
    Replies: 1
    Last Post: 08-13-2009, 07:40 PM
  3. How to select a line point to drag it ? (newbie question)
    By Sickboy in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 10-21-2003, 04:43 AM
  4. Dumb question - GLclampf - why?
    By Robbo in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 07-08-2002, 01:07 PM
  5. Vector & plane math question
    By Wulf in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-12-2001, 06:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean