////VIEWCONTROLLER.M//Pythagorean theorem////Created by Zhang Xiuqing on 15/6/8.//Copyright (c) 2015 Zhang Xiuqing. All rights reserved.//#import "ViewController.h"//Angle to radians#defineDegreestoradian (x) (m_pi*x/180.0)//Radian to Angle#defineRadianstodegrees (x) (180.0*X/M_PI)@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Cgpoint point1= Cgpointmake ( -, -); Cgpoint Point2= Cgpointmake ( $, $); CGFloat distance=[self distancebetweenpoints:point1 point2:point2]; NSLog (@"%f", distance); CGFloat Angle=[self anglebetweenpoints:point1 point2:point2]; NSLog (@"%f", Angle); //cgfloat x = (point1.x + distance) * cos (angle);//cgfloat y = (point1.y + distance) * sin (angle);// //NSLog (@ "%f---%f", x, y);}#pragmaMark-Calculates the distance between two points-(CGFloat) distancebetweenpoints: (cgpoint) point1 Point2: (cgpoint) point2{ cgfloat Distancex= point2.x-point1.x; CGFloat Distancey= Point2.y-point1.y; returnsqrt (Distancex*distancex + distancey*distancey);}#pragmaMark-Calculates the angle between two points-(CGFloat) anglebetweenpoints: (cgpoint) point1 Point2: (cgpoint) point2{cgfloat height= Point2.y-point1.y; CGFloat width= point1.x-point2.x; CGFloat rads= Atan (height/width); returnradianstodegrees (rads); }@end
Calculates the distance between two points, the slope between two points (angle)--Hidekiyo