3 points are known, and the distance from point to surface is obtained.

Source: Internet
Author: User
// Obtain the plane equation at three known points
BOOL CGe: PanelEquationFromThreePt (CPoint3dArray ptArr,
Double & a, double & B, double & c, double & d)
{// From http://blog.csdn.net/hoya5121
CPoint3d p1, p2, p3;

If (ptArr. GetSize () <3)
{
Return FALSE;
}
P1 = ptArr [0];
P2 = ptArr [1];
P3 = ptArr [2];

A = (p2.y-p1.y) * (p3.z-p1.z)-(p2.z-p1.z) * (p3.y-p1.y ));
B = (p2.z-p1.z) * (p3.x-p1.x)-(p2.x-p1.x) * (p3.z-p1.z ));
C = (p2.x-p1.x) * (p3.y-p1.y)-(p2.y-p1.y) * (p3.x-p1.x ));
D = (0-(a * p1.x + B * p1.y + c * p1.z ));

Return TRUE;
}

// The distance from the point to the surface, where the coordinate is P (x, y, z), and the plane equation is ax + by + cz + d = 0.
Double CGe: DistPt2Panel (double x, double y, double z,
Double a, double B, double c, double d)
{
Return fabs (a * x + B * y + c * z + d)/sqrt (a * a + B * B + c * c );
}

 

 

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.