已知两点坐标和三边长度,求三角形第三点的坐标

已知两点坐标和三边长度,求三角形第三点的坐标

经验证,该方法在平面中通用。

基本思路或步骤如下:

  1. 计算边AB与Y轴正向的夹角,或者叫做向量AB的航向角;
  2. 计算出角CAB的角度;
  3. 计算边AC与Y轴正向的夹角,或者是向量AC的航向角;
  4. 根据三角形的一些算法,得到对应的C点坐标
    引用自https://wenku.baidu.com/view/46038b2342323968011ca300a6c30c225801f056.html
    图片: 《已知两点坐标和三边长度,求三角形第三点的坐标》https://wenku.baidu.com/view/46038b2342323968011ca300a6c30c225801f056.html

以下为代码

博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

//根据两点坐标和边长长度,计算第三点坐标,第三点有两个
bool AutoExtraLine::Cal3rdPoint(vector<CCVector3d> vecSrcPoints, double ab, double bc, double ca, vector<CCVector3d>& vec3rdPoints)
{ 
    if (vecSrcPoints.size()<2)
    { 
        return false;
    }
    CCVector3d pointA = vecSrcPoints[0];
    CCVector3d pointB = vecSrcPoints[1];
    CCVector3d pointC;
     
    
    double dy = pointB.y - pointA.y;
    double dx = pointB.x - pointA.x;
    double tmpValue = (ca*ca + ab * ab - bc * bc) / (2 * ca*ab);
    //AB的方位角
    
    double angAB = CalVectorAngleWithY(pointA, pointB);
    if (angAB>180)
    { 
       // angAB = angAB - 180;
    }
    angAB = angAB * (PI / 180);
   // angAB = atan(dy / dx);
    //A点对应BC边的角度
    double angBC = acos(tmpValue);
    //AC的方位角
    double angAC = angAB-angBC;
    pointC.x = pointA.x + ca * sin(angAC);
    pointC.y = pointA.y + ca * cos(angAC);
    vec3rdPoints.push_back(pointC);

    angAC = angAB + angBC;
    pointC.x = pointA.x + ca * sin(angAC);
    pointC.y = pointA.y + ca * cos(angAC);
    vec3rdPoints.push_back(pointC);
    return true;
}
/计算向量ABY轴正方向夹角,角度范围0~360
double AutoExtraLine::CalVectorAngleWithY(CCVector3d pointA, CCVector3d pointB)
{ 
    //线段(startPt,firstPt)平行于y轴向上
    CCVector3d firstPt(pointA.x, pointA.y + 10, pointA.z);
    double angle = PointAlg::calcAngleByThreePoint(firstPt, pointA, pointB);
    angle = angle * 180 / PI;
    if (pointA.x > pointB.x)
    { 
        angle = 360 - angle;
    }
    return angle;
}
    原文作者:xwb_12340
    原文地址: https://blog.csdn.net/xwb_12340/article/details/85756933
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞