The distance of a line in the "c\c++" space for a point to two points __c++

Source: Internet
Author: User
Tags pow

Recently in the work of leaf reconstruction, the construction of the Leaf tin algorithm will be used to 3-dimensional midpoint to the line of the distance equation, a beginning to think like a two-dimensional formula and so on, and then find a bit did not find, wrote a function, to share

Double dis_3d (Point a,point b,point s) {
    double ab=sqrt (POW (a.x-b.x), 2.0) +pow ((A.Y-B.Y), 2.0) +pow ((A.Z-B.Z), 2.0) );
    Double as=sqrt (POW (a.x-s.x), 2.0) +pow ((A.Y-S.Y), 2.0) +pow ((A.Z-S.Z), 2.0));
    Double bs=sqrt (POW (s.x-b.x), 2.0) +pow ((S.Y-B.Y), 2.0) +pow ((S.Z-B.Z), 2.0));

    Double cos_a= (POW (as,2.0) +pow (ab,2.0)-pow (bs,2.0))/(2*ab*as);
    Double Sin_a=sqrt (1-pow (cos_a,2.0));
    return as*sin_a;
}

The basic mathematical principle is to use the cosine theorem to find the angle, and then to find the sine, and then the high,
That is, the distance from the point to the line.

Related Article

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.