kiplingw
May 6th, 2010, 05:22 AM
I have a C++ class for representing 3D coordinates called, say, Vector3. It has four components: X, Y, Z, and W. The fourth component W is always present to make working with homogeneous coordinates possible.
I would also like to represent 3D points and directions, perhaps as typedef aliases or through inheritance, I don't know. They are related to each other, but not identical.
They relate to each other as such:
direction + direction = direction
direction - direction = direction
point + direction = point
point - point = direction
point + point = N/A
Moreover, Point3 have their W coordinate set to 1 and Direction3's to 0. This is to ensure directions are not translated, but points are.
What is a good approach to enforcing this policy safely and efficiently? If you have a design pattern you'd recommend, I've got the Gang of Four right beside me. I've thought about it for a while and different approaches of templates, inheritance, and access modifiers come to mind but without clarity in this context.
Assume I have a Vector3 class with a four parameter constructor and Point3 / Direction3 need only three parameters.
Thanks :)
I would also like to represent 3D points and directions, perhaps as typedef aliases or through inheritance, I don't know. They are related to each other, but not identical.
They relate to each other as such:
direction + direction = direction
direction - direction = direction
point + direction = point
point - point = direction
point + point = N/A
Moreover, Point3 have their W coordinate set to 1 and Direction3's to 0. This is to ensure directions are not translated, but points are.
What is a good approach to enforcing this policy safely and efficiently? If you have a design pattern you'd recommend, I've got the Gang of Four right beside me. I've thought about it for a while and different approaches of templates, inheritance, and access modifiers come to mind but without clarity in this context.
Assume I have a Vector3 class with a four parameter constructor and Point3 / Direction3 need only three parameters.
Thanks :)