首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

几个适用方法:点间距离、点间角度、线间角度

2012-09-25 
几个实用方法:点间距离、点间角度、线间角度#include math.h#define pi 3.14159265358979323846#define de

几个实用方法:点间距离、点间角度、线间角度

#include <math.h>

#define pi 3.14159265358979323846
#define degreesToRadian(x) (pi * x / 180.0)
#define radiansToDegrees(x) (180.0 * x / pi)
CGFloat distanceBetweenPoints (CGPoint first, CGPoint second) {
??? CGFloat deltaX = second.x - first.x;
??? CGFloat deltaY = second.y - first.y;
??? return sqrt(deltaX*deltaX + deltaY*deltaY );
};
CGFloat angleBetweenPoints(CGPoint first, CGPoint second) {
??? CGFloat height = second.y - first.y;
??? CGFloat width = first.x - second.x;
??? CGFloat rads = atan(height/width);
??? return radiansToDegrees(rads);
??? //degs = degrees(atan((top - bottom)/(right - left)))
}
CGFloat angleBetweenLines(CGPoint line1Start, CGPoint line1End, CGPoint line2Start, CGPoint line2End) {
???
??? CGFloat a = line1End.x - line1Start.x;
??? CGFloat b = line1End.y - line1Start.y;
??? CGFloat c = line2End.x - line2Start.x;
??? CGFloat d = line2End.y - line2Start.y;
???
??? CGFloat rads = acos(((a*c) + (b*d)) / ((sqrt(a*a + b*b)) * (sqrt(c*c + d*d))));
???
??? return radiansToDegrees(rads);
???
}

?

热点排行