New +Line::intersection_infinite() method

This commit is contained in:
Alessandro Ranellucci 2015-01-16 16:25:39 +01:00
parent aa69ae11a8
commit e749f6040f
4 changed files with 33 additions and 1 deletions

View file

@ -89,6 +89,23 @@ Line::point_at(double distance) const
return p;
}
bool
Line::intersection_infinite(const Line &other, Point* point) const
{
Vector x = this->a.vector_to(other.a);
Vector d1 = this->vector();
Vector d2 = other.vector();
double cross = d1.x * d2.y - d1.y * d2.x;
if (std::fabs(cross) < EPSILON)
return false;
double t1 = (x.x * d2.y - x.y * d2.x)/cross;
point->x = this->a.x + d1.x * t1;
point->y = this->a.y + d1.y * t1;
return true;
}
bool
Line::coincides_with(const Line &line) const
{