Bresenham's 光线追踪算法,点到直线距离算法,点与多边形相交检测
来源:互联网 发布:51单片机指令集 编辑:程序博客网 时间:2024/06/06 03:40
* @brief A 2D implementation of Bresenham's raytracing algorithm... applies an action at each step
*/
template<class ActionType>
inline void bresenham2D(ActionType at, unsigned int abs_da, unsigned int abs_db, int error_b, int offset_a,
int offset_b, unsigned int offset, unsigned int max_length)
{
unsigned int end = std::min(max_length, abs_da);
for (unsigned int i = 0; i < end; ++i)
{
at(offset);
offset += offset_a;
error_b += abs_db;
if ((unsigned int)error_b >= abs_da)
{
offset += offset_b;
error_b -= abs_da;
}
}
at(offset);
}
-------------------------------------------------------------------------------
double distanceToLine(double pX, double pY, double x0, double y0, double x1, double y1)
{
double A = pX - x0;
double B = pY - y0;
double C = x1 - x0;
double D = y1 - y0;
double dot = A * C + B * D;
double len_sq = C * C + D * D;
double param = dot / len_sq;
double xx, yy;
if (param < 0)
{
xx = x0;
yy = y0;
}
else if (param > 1)
{
xx = x1;
yy = y1;
}
else
{
xx = x0 + param * C;
yy = y0 + param * D;
}
return distance(pX, pY, xx, yy);
}
--------------------------------------------------
bool intersects(std::vector<geometry_msgs::Point>& polygon, float testx, float testy)
{
bool c = false;
int i, j, nvert = polygon.size();
for (i = 0, j = nvert - 1; i < nvert; j = i++)
{
float yi = polygon[i].y, yj = polygon[j].y, xi = polygon[i].x, xj = polygon[j].x;
if (((yi > testy) != (yj > testy)) && (testx < (xj - xi) * (testy - yi) / (yj - yi) + xi))
c = !c;
}
return c;
}
---------------------------------------------------
- Bresenham's 光线追踪算法,点到直线距离算法,点与多边形相交检测
- POJ 1584 A Round Peg in a Ground Hole(点到直线距离,圆与多边形相交,多边形是否为凸)
- 光线与包围盒(AABB)的相交检测算法
- 光线与包围盒(AABB)的相交检测算法
- 光线与包围盒(AABB)的相交检测算法
- 有N个点求一条直线使得所有点到直线的距离和最小的算法
- 点到直线的距离
- 点到直线距离公式
- 点到直线的距离
- HDU1174-点到直线距离
- 点到直线的距离
- 点到直线的距离
- 点到直线平面距离
- 点到直线的距离
- 计算点到直线距离
- 点到直线的距离
- 判断是否是凸多边形,判断点是否在多边形内,点到直线的距离
- 点到线段直线的距离, 直线与直线的关系 直线与线段的关系
- servlet(doget和dopost)
- DBCP 数据库连接池
- 7-5
- 浏览器运行applet问题
- STL 格式解析--文本以及二进制格式
- Bresenham's 光线追踪算法,点到直线距离算法,点与多边形相交检测
- 为什么不能从静态的方法里面调用非静态方法,或变量?
- 自定义的xml文件 fouced与enable冲突
- 如何添加或删除ubuntu用户和组
- Android端恶意锁屏勒索应用分析
- CENTOS 6下ANDROID SDK碰到提示”LIBC.SO.6: VERSION `GLIBC_2.14′ NOT FOUND”的解决方法
- android7.0打开相册报FileUriExposedException异常
- Android自定义控件三部曲
- YAHFA--ART环境下的Hook框架(代码详解)