Hor*_*lea 6 c math geometry 2d trigonometry
我有2个点的坐标(x,y).我想建立第三个点,使这3个点成为等边三角形.
我该如何计算第三点?
谢谢
在阅读了帖子(特别是vkit)之后,我制作了这段简单的代码,它将为一个方向提供技巧(请记住,有两点).对另一案件的修改是微不足道的.
#include<stdio.h>
#include<math.h>
typedef struct{
double x;
double y;
} Point;
Point vertex(Point p1, Point p2){
double s60 = sin(60 * M_PI / 180.0);
double c60 = cos(60 * M_PI / 180.0);
Point v = {
c60 * (p1.x - p2.x) - s60 * (p1.y - p2.y) + p2.x,
s60 * (p1.x - p2.x) + c60 * (p1.y - p2.y) + p2.y
};
return v;
}
Run Code Online (Sandbox Code Playgroud)
小智 8
您可以先将第二个点旋转60°,以找到第三个点的位置.
像这样的东西:
//find offset from point 1 to 2 dX = x2 - x1; dY = y2 - y1; //rotate and add to point 1 to find point 3 x3 = (cos(60°) * dX - sin(60°) * dY) + x1; y3 = (sin(60°) * dX + cos(60°) * dY) + y1;