Logo Search packages:      
Sourcecode: javamorph version File versions  Download package

boolean javamorph::CLine::cross ( CLine  other  )  [inline]

Does one line cross the other? Hint: Except endpoints.

Parameters:
other The other line.
Returns:
true if crossing.

Definition at line 65 of file CLine.java.

References x1, x2, y1, and y2.

                                     {
        /* Initialize helper variables. */
        double
            x1 = this.x1,
            y1 = this.y1,
            x1_ = this.x2,
            y1_ = this.y2,
            x2 = other.x1,
            y2 = other.y1,
            x2_ = other.x2,
            y2_ = other.y2,
            z,
            n,
            q,
            p;
        /* Divident. */
        z = (x1_ - x1) * (y2 - y1) - (y1_ - y1) * (x2 - x1);
        /* Divisor. */
        n = (y1_ - y1) * (x2_ - x2) - (x1_ - x1) * (y2_ - y2);
        /* Is parallel? => Can't cross! */
        if(0.0 == n)return false;
        /* Quotient q. */
        q = z / n;
        /* Is len zero? */
        if(x1 == x1_ && y1 == y1_)return false;
        /* Variants depending on whether points are orthogonal. */
        if(0.0 != x1_ -x1){
            p = (x2 - x1 + q * (x2_ - x2)) / (x1_ -x1);
        }else{
            p = (y2 - y1 + q * (y2_ - y2)) / (y1_ -y1);
        }
        /* Crossing after the end of the line. */
        if(q < 0.0 || q > 1.0)return false;
        /* Crossing after the end of the line. */
        if(p < 0.0 || p > 1.0)return false;
        /* Determine whether crossing on end point. */
        Point
            p1 = new Point(this.x1, this.y1),
            p2 = new Point(this.x2, this.y2),
            p3 = new Point(other.x1, other.y1),
            p4 = new Point(other.x2, other.y2);
        /* Determine whether crossing on end point. */
        if(p1.equals(p3) || p1.equals(p4))return false;
        /* Determine whether crossing on end point. */
        if(p2.equals(p3) || p2.equals(p4))return false;
        /* No false condition fired. */
        return true;
    }


Generated by  Doxygen 1.6.0   Back to index