由网友(海阔山遥)分享简介:予有2点的坐标(x,y)的。我想建立的第三点,使这3点做出一个等边三角形。 I have the coordinates (x,y) of 2 points. I want to build the third point so that these 3 points make an equilateral tria...
予有2点的坐标(x,y)的。我想建立的第三点,使这3点做出一个等边三角形。
I have the coordinates (x,y) of 2 points. I want to build the third point so that these 3 points make an equilateral triangle.
我如何计算第三点?
感谢您
推荐答案
看完帖子后(特别是vkit的),我公司生产的这一段简单的code这会做的伎俩一个方向(记住,有两个点)。该修改的其他情况shold是微不足道的。
After reading the posts (specially vkit's) I produced this simple piece of code which will do the trick for one direction (remember that there are two points). The modification for the other case shold be trivial.
#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;
}
相关推荐
最新文章