Calculate the distance from a point to a line using a vector method

Source: Internet
Author: User

  • 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

    1. a * b = | a | * | b | * cos(x), where x is the angle of the vector A, a, b
    2. | a | * 单位向量 = a, the vector of the unit vector is modulo 1
    3. 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:

    1. 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.
    2. 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.
    3. 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
    4. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.