zoukankan      html  css  js  c++  java
  • 三点求角

    利用向量公式:
    AB·AC=|AB|·|AC|·cos(theta)

    #include<iostream>
    #include<cmath>
    
    
    int main()
    
    {
        
        //90,45,45
        //double Ax(0),Ay(0),Bx(1),By(0),Cx(0),Cy(1);
        //60,60,60
        //double Ax(0),Ay(0),Bx(1),By(sqrt(3)),Cx(2),Cy(0);
        //90,60,30
        double Ax(0),Ay(0),Bx(1),By(0),Cx(0),Cy(sqrt(3));
        
    
        double AB=sqrt(pow(Bx-Ax,2)+pow(By-Ay,2));    // |AB|
        double AC=sqrt(pow(Cx-Ax,2)+pow(Cy-Ay,2));    // |AC|
        double BC=sqrt(pow(Cx-Bx,2)+pow(Cy-By,2));    // |BC|
        
        double AB_AC=(Bx-Ax)*(Cx-Ax)+(By-Ay)*(Cy-Ay);    // AB·AC
        double BA_BC=(Ax-Bx)*(Cx-Bx)+(Ay-By)*(Cy-By);    // BA·BC
        double CA_CB=(Ax-Cx)*(Bx-Cx)+(Ay-Cy)*(By-Cy);    // CA·CB
        
        double costhetaA=AB_AC/(AB*AC);    // cos∠A
        double costhetaB=BA_BC/(AB*BC);    // cos∠B
        double costhetaC=CA_CB/(AC*BC);    // cos∠C
    
        double AngleA=acos(costhetaA)*180/3.1415926;    // ∠A
        double AngleB=acos(costhetaB)*180/3.1415926;    // ∠B
        double AngleC=acos(costhetaC)*180/3.1415926;    // ∠C
        
        
        std::cout<<AngleA<<std::endl;
        std::cout<<AngleB<<std::endl;
        std::cout<<AngleC<<std::endl;
        
        return 0;
    }
    
    
    
    90
    60
    30
    


    参考链接:
    https://wenku.baidu.com/view/61c8631311a6f524ccbff121dd36a32d7375c77c.html

  • 相关阅读:
    Vue3.0
    Vue
    Vue
    Vue3.0
    Vue
    Vue
    Vue
    Vue
    Vue3.0
    万字长文|十大基本排序,一次搞定!
  • 原文地址:https://www.cnblogs.com/chendeqiang/p/12861553.html
Copyright © 2011-2022 走看看