zoukankan      html  css  js  c++  java
  • 计算两点之间的距离,两点之间的斜率(角度)--秀清

    //
    //  ViewController.m
    //  勾股定理
    //
    //  Created by 张秀清 on 15/6/8.
    //  Copyright (c) 2015年 张秀清. All rights reserved.
    //
    
    #import "ViewController.h"
    
    //角度转弧度
    #define degreesToradian(x) (M_PI*x/180.0)
    
    //弧度转角度
    #define radiansToDegrees(x) (180.0*x/M_PI)
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        
        CGPoint point1 = CGPointMake(100, 100);
        CGPoint point2 = CGPointMake(200, 200);
        
        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);
    }
    
    #pragma mark - 计算两点间的距离
    -(CGFloat)distanceBetweenPoints:(CGPoint)point1 point2:(CGPoint)point2
    {
        CGFloat distanceX = point2.x - point1.x;
        CGFloat distanceY = point2.y - point1.y;
        
        return sqrt(distanceX*distanceX + distanceY*distanceY);
    }
    
    #pragma mark - 计算两点间的角度
    -(CGFloat)angleBetweenPoints:(CGPoint)point1 point2:(CGPoint)point2
    {
        CGFloat height = point2.y - point1.y;
        CGFloat width  = point1.x - point2.x;
        
        CGFloat rads   = atan(height/width);
        
        return radiansToDegrees(rads);
        
    }
    
    
    @end
  • 相关阅读:
    HDU 1003 Max Sum
    HDU 1728 逃离迷宫
    UVA 10057 A midsummer night's dream.
    HDU 1232 畅通工程
    poj3331
    poj3481
    poj1053
    poj3281
    poj3199
    !!! Gridview的多种使用方法总结
  • 原文地址:https://www.cnblogs.com/sixindev/p/4561193.html
Copyright © 2011-2022 走看看