I am working with computer graphics.
I would like to represent a line with two end points, and, then I would like my Line2d class to have a method that
If you want to convert a line segment to a vector, you have to be aware that there is no "universal semantic" for the conversion, it is up to you to define what the conversion means. That said, I assume you want a vector with the same (Euclidean) norm as the length of the line segment and pointing in the same direction, i.e. something like this:
class LineSegment2d
{
....
Vector2d getVector() const {
return Vector2d(end) - Vector2d(start);
}
};
In other words, offset the line segment to the origin point of the coordinate system. The end point can then be converted to a vector.
EDIT: After understanding a bit more about why you want this, you might be looking for another representation
class LineSegment2d
{
....
Vector2d getVector() const {
return Vector2d(end);
}
};
This will get you one vector for each line segment: the end point. If your polygons consist of connected line segments, this will give you all the vertices in the polygon.