如何找到在C中的2D等边三角形的坐标? [英] How to find coordinates of a 2d equilateral triangle in C?
本文介绍了如何找到在C中的2D等边三角形的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
予有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;
}
这篇关于如何找到在C中的2D等边三角形的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文