PointsCalculation.h文件
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#ifndef max
#define max(a,b)
#endif
#ifndef min
#define min(a,b)
#endif
#define degreesToRadian(x) (M_PI * x / 180.0)
#define radiansToDegrees(x) (180.0 * x / M_PI)
@interface PointsCalculation : NSObject {
}
+(CGFloat)widthBetweenPoints:(CGPoint) first:(CGPoint) second;
+(CGFloat)heightBetweenPoints:(CGPoint) first:(CGPoint) second;
+(CGFloat)distanceBetweenPoints:(CGPoint) first:(CGPoint) second;
+(CGFloat)angleBetweenPoints:(CGPoint)left:(CGPoint) right;
+(CGFloat)angleBetweenThreePoints:(CGPoint)first:(CGPoint)second:(CGPoint)third;
+(CGFloat)angleBetweenLines:(CGPoint)line1Start:(CGPoint)line1End:(CGPoint)line2Start:(CGPoint)line2End;
+ (NSInteger)createRandomsizeValueInt
+ (double)createRandomsizeValueFlo
@end
PointsCalculation.m文件
#import "PointsCalculation.h"
#include <math.h>
@implementation PointsCalculation
//!随机数的最大值
#define ARC4RANDOM_MAX
+ (NSInteger)createRandomsizeValueInt
{
}
+ (double)createRandomsizeValueFlo
{
}
+(CGFloat)widthBetweenPoints:(CGPoint) first:(CGPoint) second
{
CGFloat deltaX = second.x - first.x;
if (deltaX > 0) {
return deltaX;
}
else {
return deltaX*(-1);
}
}
+(CGFloat)heightBetweenPoints:(CGPoint) first:(CGPoint) second
{
CGFloat deltaY = second.y - first.y;
if (deltaY > 0) {
return deltaY;
}
else {
return deltaY*(-1);
}
}
+(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)left:(CGPoint) right{
CGFloat height = right.y - left.y;
CGFloat width = left.x - right.x;
CGFloat rads =0;
if(width!=0){
}
//return radiansToDegrees(rads);
return rads;
//degs = degrees(atan((top - bottom)/(right - left)))
}
+(CGFloat)angleBetweenThreePoints:(CGPoint)first:(CGPoint)second:(CGPoint)third{
CGFloat height1 = second.y - first.y;
CGFloat width1 = first.x - second.x;
CGFloat rads1=0;
if(width1!=0){
rads1 = atan(height1/width1);
}
CGFloat height2 = third.y - first.y;
CGFloat width2 = third.x - second.x;
CGFloat rads2 =0;
if(width2!=0){
rads2 = atan(height2/width2);
}
CGFloat rads=rads2-rads1;
return radiansToDegrees(rads);
}
+(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);
}
@end