Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are correct answers already, but I think it might be more generally useful to have a formula that gives the distance of any point from a specified line. Then you can just check if this is zero, or within whatever tolerance you choose. The following should work regardless of special cases like vertical lines (infinite gradient).</p> <p>The distance of point <em>X</em> from the line <em>AB</em> is</p> <p>    <a href="http://hypftier.de/dump/SO-6276361-Ben-1.png" rel="nofollow noreferrer">http://hypftier.de/dump/SO-6276361-Ben-1.png</a></p> <p>where <em>A</em>, <em>B</em> and <em>X</em> are the 3D position vectors of the three points (just set <em>z</em> = 0 if you are only working in 2D) and <em>x</em> is the vector product. That comes to</p> <p>    <a href="http://hypftier.de/dump/SO-6276361-Ben-2.png" rel="nofollow noreferrer">http://hypftier.de/dump/SO-6276361-Ben-2.png</a></p> <p>where <em>A</em> = (a,b), <em>B</em> = (c,d) and <em>X</em> = (x,y). Then to check that the point is actually within the line segment and not elsewhere on the infinite line, you can use the scalar products: the distance of <em>X</em> along the line from <em>A</em> to <em>B</em> is</p> <p>    <a href="http://hypftier.de/dump/SO-6276361-Ben-3.png" rel="nofollow noreferrer">http://hypftier.de/dump/SO-6276361-Ben-3.png</a></p> <p>i.e.</p> <p>    <a href="http://hypftier.de/dump/SO-6276361-Ben-4.png" rel="nofollow noreferrer">http://hypftier.de/dump/SO-6276361-Ben-4.png</a></p> <p>and this should lie between 0 and <a href="http://hypftier.de/dump/SO-6276361-Ben-5.png" rel="nofollow noreferrer">http://hypftier.de/dump/SO-6276361-Ben-5.png</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload