* p argument is the crossing point coordinates (dummy for 0 or 2
* result)
*/
-uint8_t
+uint8_t
intersect_line(const line_t *l1, const line_t *l2, point_t *p)
-{
+{
double tmp1, tmp2;
- debug_printf("l1:%2.2f,%2.2f,%2.2f l2:%2.2f,%2.2f,%2.2f\n",
+ debug_printf("l1:%2.2f,%2.2f,%2.2f l2:%2.2f,%2.2f,%2.2f\n",
l1->a, l1->b, l1->c, l2->a, l2->b, l2->c);
/* if dummy lines */
if ((l1->a == 0 && l1->b == 0) || (l2->a == 0 && l2->b == 0))
return 0;
-
+
if (l1->a == 0) {
if (l2->a == 0) {
if (l1->b*l2->c == l2->b*l1->c)
return 2;
return 0;
}
-
+
/* by + c = 0
* a'x + b'y + c' = 0 */
/*
p->x = -(l2->b*(-l1->c) + l2->c*l1->b)/(l2->a*l1->b);
return 1;
}
-
+
if (l1->b == 0) {
if (l2->b == 0) {
if (l1->a*l2->c == l2->a*l1->c)
p1y = p1->y;
p2x = p2->x;
p2y = p2->y;
-
+
l->a = -(p2y - p1y);
l->b = (p2x - p1x);
l->c = -(l->a * p1x + l->b * p1y);
-
+
debug_printf("%s: %2.2f, %2.2f, %2.2f\r\n",
__FUNCTION__, l->a, l->b, l->c);
}
/* return values:
* 0 dont cross
- * 1 cross
+ * 1 cross
* 2 cross on point
* 3 parallel and one point in
*
* p argument is the crossing point coordinates (dummy for 0 1 or 3
* result)
*/
-uint8_t
-intersect_segment(const point_t *s1, const point_t *s2,
- const point_t *t1, const point_t *t2,
+uint8_t
+intersect_segment(const point_t *s1, const point_t *s2,
+ const point_t *t1, const point_t *t2,
point_t *p)
{
line_t l1, l2;
*p = *s2;
return 2;
}
-
+
debug_printf("px=%" PRIi32 " py=%" PRIi32 "\n", p->x, p->y);
/* Consider as parallel if intersection is too far */
return 1;
}
+
+void line_translate(line_t *l, vect_t *v)
+{
+ l->c -= (l->a * v->x + l->b * v->y);
+}