计算两点之间的距离,两点之间的斜率(角度)--秀清
2015-06-08 16:05
501 查看
// // 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
相关文章推荐
- Windowform 窗体关联数据库存储,读取图片,参考代码
- DataSet,DataTable,XML格式互转
- linux下GBK->UTF-8文件编码批量转换脚本
- Eclipse debug常用基本技巧
- Java泛型 泛型类型的继承规则
- 《我如何自己做自己的导师》
- GDB(九) 观察和改变变量
- DEV控件之ChartControl 属性设置
- aspx页面Page_Load和aspx页面上控件Page_Load事件执行顺序
- 字符串加密解密
- PHPWord利用模板替换字符串生成精确的word文档
- Mosquito的优化——其他优化(九)
- linux的环境变量问题
- SQL左右连接中的on and和on where的区别
- DOM操作表格
- LoadLibrary失败的原因(转)
- centos6.5安装mysql5.6
- linux文件是否被当前进程外的其他进程打开
- 25_android下文件访问的权限
- CString 操作