コード例 #1
0
bool intersection_point(line l1, line l2, point2d *p)
{
	if (same_lineQ(l1, l2)) {
		p->x = p->y = 0.0;
		return true;
	}
	if (parallelQ(l1,l2) == true) {
		return false;
	}

	p->x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b);
	if (fabs(l1.b) > EPSILON)	// test for vertical line
		p->y = - (l1.a * p->x + l1.c) / l1.b;
	else
		p->y = - (l2.a * p->x + l2.c) / l2.b;

	return true;
}
コード例 #2
0
ファイル: geometry.c プロジェクト: armenr/algorist
void intersection_point(line l1, line l2, point p) {
	if(same_lineQ(l1, l2)) {
		printf("Warning: Identical lines, all points intersect.\n");
		p[X] = p[Y] = 0.0;
		return;
	}

	if(parallelQ(l1, l2) == TRUE) {
		printf("Error: Distinct parallel lines do not intersect.\n");
		return;
	}

	p[X] = (l2.b*l1.c - l1.b*l2.c) / (l2.a*l1.b - l1.a*l2.b);

	if(fabs(l1.b) > EPSILON)	/* test for vertical line */
		p[Y] = - (l1.a * (p[X]) + l1.c) / l1.b;
	else
		p[Y] = - (l2.a * (p[X]) + l2.c) / l2.b;
}
コード例 #3
0
ファイル: geometry.c プロジェクト: armenr/algorist
bool segments_intersect(segment s1, segment s2) {
	line l1, l2;		/* lines containing the input segments */
	point p;		/* intersection point */

	points_to_line(s1.p1, s1.p2, &l1);
	points_to_line(s2.p1, s2.p2, &l2);

	if(same_lineQ(l1, l2)) 	/* overlapping or disjoint segments */
		return( point_in_box(s1.p1, s2.p1, s2.p2) ||
			point_in_box(s1.p2, s2.p1, s2.p2) ||
			point_in_box(s2.p1, s1.p1, s1.p2) ||
			point_in_box(s2.p2, s1.p1, s1.p2) );

	if(parallelQ(l1, l2)) return(FALSE);

	intersection_point(l1, l2, p);

	return( point_in_box(p, s1.p1, s1.p2) && point_in_box(p, s2.p1, s2.p2) );
}
コード例 #4
0
bool segments_intersect(segment s1, segment s2)
{
	line l1, l2;

	points_to_line(s1.p1, s1.p2, &l1);
	points_to_line(s2.p1, s2.p2, &l2);

	if (same_lineQ(l1, l2))
		return (point_in_box(s1.p1, s2.p1, s2.p2) ||
				point_in_box(s1.p2, s2.p1, s2.p2) ||
				point_in_box(s2.p1, s1.p1, s1.p2) ||
				point_in_box(s2.p1, s1.p1, s1.p2) );
	
	if (parallelQ(l1, l2)) 
		return false;
	
	point2d p;		// intersection point
	intersection_point(l1, l2, p);
	return (point_in_box(p, s1.p1, s1.p2) && point_in_box(p, s2.p1, s2.p2) );
}