Class Hierarchy Question
Right now this is my setup:
I have these classes
Point2
Point3
Vector2
Vector3
Ray2
Ray3
Both Point classes and both Vector are independent. Ray2 contains a Point2 and a Vector2 object, and Ray3 contains a Point3 and a Vector3 object.
I have two questions.
1) Should I somehow just have a Point class that has a way to make a Point2 and a Point3 (and same for the Vector classes)
2) As I mentioned, the Ray classes just contain a Point and a Vector of the same dimension as the ray. Should this be a separate class? or again somehow derived from one of the other ones?
I have a very basic understanding of this idea and of virtual classes- if you have a class "animal" it doesn't make sense to give it a name, you first have to make a subclass "dog" before you can name it, but I've never implemented either of these ideas so I'm not sure when to apply them.
Any light you can shed will be much appreciated!
Thanks,
Dave
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
Point2 contains
double x, y;
Point3 contains
double x,y,z;
but they have different functions. Well in the case of Point they dont really have any functions at all, but with like my Line2 class, it has an IntersectLine() function that uses the y=mx+b type equations, which clearly do not apply in 3d. so my Line3 should also have an IntersectLine() function, but it will be very different.
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
sure sure, but then how does it know which functions to use? Like then I'd have to have an Intersect2 and an Intersect3 function , right? So we've just moved the problem?
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204