Logo Search packages:      
Sourcecode: inkscape version File versions

IntersectorKind Geom::line_intersection ( Geom::Point const &  n0,
double const   d0,
Geom::Point const &  n1,
double const   d1,
Geom::Point result 
)

Finds the intersection of the two (infinite) lines defined by the points p such that dot(n0, p) == d0 and dot(n1, p) == d1.

If the two lines intersect, then result becomes their point of intersection; otherwise, result remains unchanged.

This function finds the intersection of the two lines (infinite) defined by n0.X = d0 and x1.X = d1. The algorithm is as follows: To compute the intersection point use kramer's rule:

 * convert lines to form
 * ax + by = c
 * dx + ey = f
 *
 * (
 *  e.g. a = (x2 - x1), b = (y2 - y1), c = (x2 - x1)*x1 + (y2 - y1)*y1
 * )
 *
 * In our case we use:
 *   a = n0.x     d = n1.x
 *   b = n0.y     e = n1.y
 *   c = d0        f = d1
 *
 * so:
 *
 * adx + bdy = cd
 * adx + aey = af
 *
 * bdy - aey = cd - af
 * (bd - ae)y = cd - af
 *
 * y = (cd - af)/(bd - ae)
 *
 * repeat for x and you get:
 *
 * x = (fb - ce)/(bd - ae)                

If the denominator (bd-ae) is 0 then the lines are parallel, if the numerators are 0 then the lines coincide.

Todo:
Why not use existing but outcommented code below (HAVE_NEW_INTERSECTOR_CODE)?
Finds the intersection of the two (infinite) lines defined by the points p such that dot(n0, p) == d0 and dot(n1, p) == d1.

If the two lines intersect, then result becomes their point of intersection; otherwise, result remains unchanged.

This function finds the intersection of the two lines (infinite) defined by n0.X = d0 and x1.X = d1. The algorithm is as follows: To compute the intersection point use kramer's rule:

 * convert lines to form
 * ax + by = c
 * dx + ey = f
 *
 * (
 *  e.g. a = (x2 - x1), b = (y2 - y1), c = (x2 - x1)*x1 + (y2 - y1)*y1
 * )
 *
 * In our case we use:
 *   a = n0.x     d = n1.x
 *   b = n0.y     e = n1.y
 *   c = d0        f = d1
 *
 * so:
 *
 * adx + bdy = cd
 * adx + aey = af
 *
 * bdy - aey = cd - af
 * (bd - ae)y = cd - af
 *
 * y = (cd - af)/(bd - ae)
 *
 * repeat for x and you get:
 *
 * x = (fb - ce)/(bd - ae)                

If the denominator (bd-ae) is 0 then the lines are parallel, if the numerators are 0 then the lines coincide.

Todo:
Why not use existing but outcommented code below (HAVE_NEW_INTERSECTOR_CODE)?

Definition at line 60 of file geom.cpp.

Referenced by line_segment_intersect(), line_twopoint_intersect(), and segment_intersect().

{
    double denominator = dot(Geom::rot90(n0), n1);
    double X = n1[Geom::Y] * d0 -
        n0[Geom::Y] * d1;
    /* X = (-d1, d0) dot (n0[Y], n1[Y]) */

    if (denominator == 0) {
        if ( X == 0 ) {
            return coincident;
        } else {
            return parallel;
        }
    }

    double Y = n0[Geom::X] * d1 -
        n1[Geom::X] * d0;

    result = Geom::Point(X, Y) / denominator;

    return intersects;
}


Generated by  Doxygen 1.6.0   Back to index