计算相对角度的两个函数
来源:互联网 发布:淘宝二维码制作 编辑:程序博客网 时间:2024/05/19 08:25
有时候需要计算点点之间的相对角度,使用arctan等需要考虑符号问题,而且比较慢,如果只需要用来比较或排序,可以完全不用计算精确大小。
下面是两个函数,可以完美解决,返回值是单调的~~
pseudoangle
// Returns the pseudoangle between the line p1 to (infinity, p1.y) // and the line from p1 to p2. The pseudoangle has the property // that the ordering of points by true angle anround p1 and // ordering of points by pseudoangle are the same The result is// in the range [0, 4) (or error -1). float pseudoangle(const WPoint& p1, const WPoint& p2) { WVector delta = p2 - p1; float result; if ((delta.x == 0) && (delta.y == 0)) { return -1; } else { result =(float) (delta.y / (abs(delta.x) + abs(delta.y))); if (delta.x < 0.0) { result = 2.0f - result; } else { result = 4.0f + result; } } return result;}
Fowler Angles
from:http://paulbourke.net/geometry/fowler//* This function is due to Rob Fowler. Given dy and dx between 2 points A and B, we calculate a number in [0.0, 8.0) which is a monotonic function of the direction from A to B. (0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0) correspond to ( 0, 45, 90, 135, 180, 225, 270, 315, 360) degrees, measured counter-clockwise from the positive x axis.*/double FowlerAngle(dy,dx)double dy,dx;{ double adx, ady; /* Absolute Values of Dx and Dy */ int code; /* Angular Region Classification Code */ adx = (dx < 0) ? -dx : dx; /* Compute the absolute values. */ ady = (dy < 0) ? -dy : dy; code = (adx < ady) ? 1 : 0; if (dx < 0) code += 2; if (dy < 0) code += 4; switch (code) { case 0: return (dx==0) ? 0 : ady/adx; /* [ 0, 45] */ case 1: return (2.0 - (adx/ady)); /* ( 45, 90] */ case 3: return (2.0 + (adx/ady)); /* ( 90,135) */ case 2: return (4.0 - (ady/adx)); /* [135,180] */ case 6: return (4.0 + (ady/adx)); /* (180,225] */ case 7: return (6.0 - (adx/ady)); /* (225,270) */ case 5: return (6.0 + (adx/ady)); /* [270,315) */ case 4: return (8.0 - (ady/adx)); /* [315,360) */ }}
- 计算相对角度的两个函数
- 计算两个文件的相对路径(php)
- 计算两个路径的相对路径
- 计算两个文件的相对路径
- 计算两个文件的相对路径
- php 计算两个文件的相对路径
- php计算两个文件的相对路径
- PHP 计算两个文件的相对路径
- 两个经纬度坐标,计算角度
- 通过传入的两个点计算他们之间的角度
- 计算两个文件的相对路径的递归算法
- php 计算两个文件之间的相对路径方法
- 算法--计算两个绝对路径之间的相对路径
- java计算两个经纬度相对的方向角
- php源码之计算两个文件的相对路径
- 一个php笔试题:两个文件相对路径的计算
- unity 一个物体相对另一个物体坐标系的偏转角度计算
- 取平面坐标相对角度(0-359度)及两角的相对角偏移量的函数
- 软件开发的反思之二--软件失败真相
- CS安装卸载测试总结
- List<T>用法
- OpenGL之曲面和曲线
- Hello Nana C++ Library
- 计算相对角度的两个函数
- S3C6410芯片揭密之一 S3C6410体系结构
- lower_bound 用法
- qemu启动虚拟机
- Quartz在Spring中设置动态定时任务
- vc resource 文件在另一个编辑器中打开
- hdu 2514 Another Eight Puzzle
- Fedora Gnome3 系统设置
- c++内存分布,代码段、全局数据区、栈、堆