Results 1 to 3 of 3

Thread: [RESOLVED] Finding a point on a line

  1. #1

    Thread Starter
    Member RaZeR's Avatar
    Join Date
    Jan 2009
    Location
    Russia, Moscow
    Posts
    38

    Resolved [RESOLVED] Finding a point on a line

    I'm really stuck at this problem
    I have a line with coordinates (X1, Y1)-(X2, Y2) and a point C on that line. I know X coordinate of this point, but i need to know Y coordinate of this point.
    Here is a sample image:


    Please help me!
    VB 6, VB.NET, C#, Java, JavaME, C/C++ and Assembler Programmer


    If my post was helpful, rate me

  2. #2
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Finding a point on a line

    The slope of a line can be found given any two points on the line. To calculate the slope, divide the difference in the Y-values by the difference in X-values.

    Slope = (Y2 - Y1)/(X2 - X1)
    Slope = (Y3 - Y1)/(X3 - X1)

    This obviously implies that (Y3 - Y1)/(X3 - X1) = (Y2 - Y1)/(X2 - X1)
    Solving for Y3, you get: Y3 = Y1 + (X3 - X1)(Y2 - Y1)/(X2 - X1)

  3. #3
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431

    Re: Finding a point on a line

    Just as an edge case, you might have a vertical line in which case the above formula will throw a division by zero, since the question isn't well defined. Of course it depends on the problem, just wanted to bring it up in case it would cause a bug later.
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

Posting Permissions

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



Click Here to Expand Forum to Full Width