pointAlongLineSegment method
Computes a Point along the line segment with a given distance to the start Point.
@param distance distance from start point @return point at given distance from start point
Implementation
Mappoint pointAlongLineSegment(double distance) {
if (start.x == end.x) {
// we have a vertical line
if (start.y > end.y) {
return Mappoint(start.x, start.y - distance);
} else {
return Mappoint(start.x, start.y + distance);
}
} else {
double slope = (end.y - start.y) / (end.x - start.x);
double fraction = distance / length();
double dx = (end.x - start.x) * fraction;
return Mappoint(start.x + dx, start.y + slope * dx);
}
}