- The method of using vectors is more efficient and simpler.
- The first thing to know is what is a vector, what is the modulus of the vector
Mainly used in the analytic geometry of a few formulas
a * b = | a | * | b | * cos(x), where x is the angle of the vector A, a, b
| a | * 单位向量 = a, the vector of the unit vector is modulo 1
- The addition and subtraction of vectors, as shown in
- Addition of vectors
- Subtraction of vectors
The prototype of the problem is as shown, the red dots are the mouse position, the blue dots (x0,y0), (x1,y1) are the endpoints of the line segments, and the distance from the red point to the straight line
You can convert a point-to-line distance to a right triangle problem, as shown in:
- We define the mouse point is M, the beginning of the line is a, the end point is b,ma vector a,ab is vector b, vector c is vector A on the vector b projection, vector e is M point to ab perpendicular, the key is to find out the modulus of the vector e.
- To get the modulus of the vector e, first to get the vector e, and to get the vector e need to get vector C, the problem is converted in order to find the vector c.
- The Pythagorean theorem is available.
|c| = |a| * cos(x), X is the angle of the vector AB, and
|a| * cos(x) = |a| * |b| * cos(x) / |b| = a * b / |b|, so you get the C modulus so you can getc = |c| * 单位向量,
Because C and B are in the same direction, take单位向量=b / |b|, sorting can be done by:
C= a span class= "Mo" id= "mathjax-span-627" style= "font-family:mathjax_main; Padding-left:0.22em; " >? b | b | b | b |
= (a? b )|b| 2 b
- After getting the vector of C, we can get the vector and
e = a - c then take the e modulus to get the distance from the point to the straight line.
Last two photos from https://msdn.microsoft.com/en-us/library/ms969920.aspx
Calculate the distance from a point to a line using a vector method