Calculates the distance between two points, the slope between two points (angle)--Hidekiyo

Source: Internet
Author: User

////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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.