|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Distance between a line and a pointI'm programming in VB .Net but this might be more a trigonometry problem.
i've been searching every maths book i can find and i haven't found anything i can use with VB. So, what i need to know is how to calculate the distance, between a line (defined by two points) and a third point, to that line (the lesser distance) My thanks in advanced > I'm programming in VB .Net but this might be more a trigonometry between a lineproblem. > i've been searching every maths book i can find and i haven't found anything > i can use with VB. > So, what i need to know is how to calculate the distance, > (defined by two points) and a third point, to that line (the Below is a section of code I've taken from another program of minelesser distance) that gives you what you want. I've left the comments in place in case that helps you any. There are only 4 lines of actual executing code... the 3 lines starting with A=, B= and C= plus the last line starting with DistPtToLine= (which yields the answer you are seeking). ' If you take the general formula for a line ' y = mx + b and substitute two points (X1, Y1) ' and (X2, Y2) into it one at a time, solve the two ' equations simultaneously and then manipulate it ' into the more general equation Ax + By + C = 0, ' you eventually arrive at the solution for A, B, C. A = Y2 - Y1 B = X1 - X2 C = X2 * Y1 - Y2 * X1 ' We do the above because knowing A, B, C for the ' above more general formula for a line allows us ' to use the following formula for the offset ' distance from any point (PX, PY) to the above ' described line: DistPtToLine = Abs((A * PX + B * PY + C) / _ Sqr(A * A + B * B)) Rick
VB 6, SP 5 and Hyperthread
Organizing Constants for Easier Maintenance Give Focus to Background Form Count Numerous Matches Only Once VB6: What's the command that creates an ARRAY out of a STRING??? XP Styles and Web Browser control GDI API question X 2 VB6: Toolbar button sizeing... Sharing violation when trying to delete a file. word hyperlink + command line args |
|||||||||||||||||||||||