Exemple #1
0
    public Vector2 intersectionPoint(CSGsegment other)//can optimize by removing redundant slope&yinter calculations
    {
        if (this.end.x == this.start.x && other.start.x == other.end.x)
        {
            throw new Exception("Vertical overlapping lines");
            //Debug.Log("Vertical overlapping lines");
            //return this.end;
        }
        if (this.end.x == this.start.x)
        {
            return(new Vector2(this.start.x, other.getSlope() * this.start.x + other.getYInter()));
        }
        else if (other.end.x == other.start.x)
        {
            return(new Vector2(other.start.x, this.getSlope() * other.start.x + this.getYInter()));
        }
        var num   = this.getYInter() - other.getYInter();
        var denom = other.getSlope() - this.getSlope();
        var x     = num / denom;

        return(new Vector2(x, x * this.getSlope() + this.getYInter()));
    }