如何在C中找到二维等边三角形的坐标? [英] How to find coordinates of a 2d equilateral triangle in C?
本文介绍了如何在C中找到二维等边三角形的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 2 个点的坐标 (x,y).我想建立第三个点,使这三个点组成一个等边三角形.
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 的)后,我编写了这段简单的代码,它可以为一个方向解决问题(请记住,有两点).其他情况的修改应该是微不足道的.
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中找到二维等边三角形的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文