Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Nearest point on a line.

Nearest point on a line.

Scheduled Pinned Locked Moved C#
question
9 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve_
    wrote on last edited by
    #1

    Hi, I have a (straight) line between two Point's. I want to find the nearest point on that line to another arbitrary point. How can I do this? Thanks, Steve

    M L M L 4 Replies Last reply
    0
    • S Steve_

      Hi, I have a (straight) line between two Point's. I want to find the nearest point on that line to another arbitrary point. How can I do this? Thanks, Steve

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      off top of head just loop through all points in the line and calulate the distance from that point to the 'other point' with pythagorus theory or something. shortest distance = nearest point maybe would be easier to apply roation to the line and point first so the line is completely vertical then just use the yPos of the point and match it to the yPos within the line

      Life goes very fast. Tomorrow, today is already yesterday.

      modified on Wednesday, March 18, 2009 11:19 AM

      1 1 Reply Last reply
      0
      • S Steve_

        Hi, I have a (straight) line between two Point's. I want to find the nearest point on that line to another arbitrary point. How can I do this? Thanks, Steve

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        StephenWhitfield wrote:

        I have a (straight) line between two Point's. I want to find the nearest point on that line to another arbitrary point. How can I do this?

        Wouldn't the answer to that be the adjacent points in either direction, or am I missing something? :confused: Ah I see, the arbitrary point is not on the line.

        1 Reply Last reply
        0
        • S Steve_

          Hi, I have a (straight) line between two Point's. I want to find the nearest point on that line to another arbitrary point. How can I do this? Thanks, Steve

          M Offline
          M Offline
          moon_stick
          wrote on last edited by
          #4

          If you say the line runs between points A and B, the nearest point on this line C to an arbitrary point X is such that AB is perpendicular to CX. It's a long time since I've done any graphics work but this sounds like it should be solved with some basic trigonometry??

          It definitely isn't definatley

          1 Reply Last reply
          0
          • M musefan

            off top of head just loop through all points in the line and calulate the distance from that point to the 'other point' with pythagorus theory or something. shortest distance = nearest point maybe would be easier to apply roation to the line and point first so the line is completely vertical then just use the yPos of the point and match it to the yPos within the line

            Life goes very fast. Tomorrow, today is already yesterday.

            modified on Wednesday, March 18, 2009 11:19 AM

            1 Offline
            1 Offline
            12Code
            wrote on last edited by
            #5

            loop through all points in the line

            How to do that?

            Kelvin

            M 1 Reply Last reply
            0
            • S Steve_

              Hi, I have a (straight) line between two Point's. I want to find the nearest point on that line to another arbitrary point. How can I do this? Thanks, Steve

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              This thread on GameDev[^] might be useful.

              1 Reply Last reply
              0
              • 1 12Code

                loop through all points in the line

                How to do that?

                Kelvin

                M Offline
                M Offline
                musefan
                wrote on last edited by
                #7

                hmmm... well do a search for 'line drawing algorithm'[^] or something like that. instead of drawing each pixel, you use each pixel to check distance with other point

                Life goes very fast. Tomorrow, today is already yesterday.

                M 1 Reply Last reply
                0
                • M musefan

                  hmmm... well do a search for 'line drawing algorithm'[^] or something like that. instead of drawing each pixel, you use each pixel to check distance with other point

                  Life goes very fast. Tomorrow, today is already yesterday.

                  M Offline
                  M Offline
                  moon_stick
                  wrote on last edited by
                  #8

                  Or you could google for nearest point on a line[^] and get a geometric solution!? :)

                  It definitely isn't definatley

                  M 1 Reply Last reply
                  0
                  • M moon_stick

                    Or you could google for nearest point on a line[^] and get a geometric solution!? :)

                    It definitely isn't definatley

                    M Offline
                    M Offline
                    musefan
                    wrote on last edited by
                    #9

                    ;) There are many ways to do many things

                    Life goes very fast. Tomorrow, today is already yesterday.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups