线的交点 [英] Line intersection

查看:136
本文介绍了线的交点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到一个行是否拦截在多边形

How to find whether a line intercepted in a polygon

推荐答案

您可以在此实现在某些网页中读出一个合理的答案

You can read a reasonable answer from this implementation found in some webpage

Point  * intersection2(Point * _line1, Point * _line2) {

Point  p1,p2,p3,p4;
p1=_line1[0]; p3=_line2[0];
p2=_line1[1]; p4=_line2[1];

// Store the values for fast access and easy
// equations-to-code conversion
double x1 = p1.x, x2 = p2.x, x3 = p3.x, x4 = p4.x;
double y1 = p1.y, y2 = p2.y, y3 = p3.y, y4 = p4.y;

double A1 = y2-y1;
double B1 = x1-x2;
double C1 = (A1*x1)+(B1*y1);

double A2 = y4-y3;
double B2 = x3-x4;
double C2 = A2*x3+B2*y3;

double det = A1*B2 - A2*B1;

if (det==0){
	return NULL;
}else{
	// Return the point of intersection
	Point  * ret = new CvPoint2D64f ();
	ret->x = (B2*C1 - B1*C2)/det;
	ret->y = (A1*C2 - A2*C1)/det;
	return ret;

}

}

参考。 C ++示例:几何概念相交线及其应用,2D绘图 通过lbackstrom 从现场天亚社code

Reference. C++ Example: Geometry Concepts Line Intersection and its Applications, 2D drawing By lbackstrom from site ucancode

这篇关于线的交点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆