首页 > 其他 > 详细

【计算几何】三点求角度

时间:2021-08-01 13:02:10      阅读:15      评论:0      收藏:0      [点我收藏+]
#include <iostream>
#include <cmath>
#define M_PI acos(-1.0)
using namespace std;

/*
get angle ACB, point C is the center point
A(x1,y1)
B(x2,y2)
C(x3,y3)
*/
double get_angle(double x1, double y1, double x2, double y2, double x3, double y3) {
	double theta = atan2(x1 - x3, y1 - y3) - atan2(x2 - x3, y2 - y3);
	if (theta > M_PI)
		theta -= 2 * M_PI;
	if (theta < -M_PI)
		theta += 2 * M_PI;

	theta = abs(theta * 180.0 / M_PI);
	return theta;
}

int main() {
	double x1 = 0;
	double y1 = 1;
	double x2 = 1;
	double y2 = 0;
	double x3 = -1;
	double y3 = -2;
	double angle1 = get_angle(x3, y3, x1, y1, x2, y2);
	double angle2 = get_angle(x1, y1, x2, y2, x3, y3);
	double angle3 = get_angle(x2, y2, x3, y3, x1, y1);
	cout << angle2 << endl;
	cout << angle3 << endl;
	cout << angle1 << endl;

	return 0;
}



【计算几何】三点求角度

原文:https://www.cnblogs.com/Tecode/p/15086162.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!