Calculating the coordinates of the third point of a triangle

前端 未结 2 1032
半阙折子戏
半阙折子戏 2021-01-23 05:50

OK, I know this sounds like it should be asked on math.stackoverflow.com, but this is embarrassingly simple maths that I\'ve forgotten from high-school, rather than advanced pos

2条回答
  •  情歌与酒
    2021-01-23 06:54

    EDIT: I had a serious brainfart previously, but this should work. Use the law of cosines

    /* use the law of cosines to get the angle of CAB */
    c² = a² + b² - 2ab cos(Cangle)
    cos(Cangle) = (a²+b²-c²) / 2ab
    Cangle = acos((a²+b²-c²) / 2ab)
    
    AB = B.xy - A.xy;
    normalize(AB);
    len = length(AC)
    C.x = len*AB.x* cos(Cangle) * len*AB.y*sin(Cangle);
    C.y = len*AB.x*-sin(Cangle) * len*AB.y*cos(Cangle);
    

提交回复
热议问题