How can I represent a vector equation of a line segment in C++?

后端 未结 6 1887
青春惊慌失措
青春惊慌失措 2021-01-19 17:59

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

6条回答
  •  北海茫月
    2021-01-19 18:24

    Your representation of class LineSegment2d is fine. But the representation of class Vector2d is incorrect. This is because you are considering only those vectors that pass through the origin. A vector on a 2d plane can be represented with 3 components in the same way it done in 3d space. The 3 components of a vector are namely: Direction, Magnitude and A point through which it passes. If we define x, y and z axes for a 3d space then, for a point in the x-y plane z component is equal to 0. Also, direction in 3d space is defined in the form of direction cosines(ie. the cosine of the angle between the vector and an axis). Hence cosine of angle between vector and z-axis is equal to zero(because the angle = 90 degrees) for a vector in x-y plane.

提交回复
热议问题