I recently got an answer to something that's been bugging me for quite a while.
When you first learned about
vectors, the teacher probably drew an arrow and said this arrow, x, represents a displacement!, or something similar. Then the teacher probably said something like
Suppose we are at some point x [draws arrow from an origin to some point]
(
Read more... )
Comments 5
OK OK. I figure it was only to keep the post on a single topic. I've always found it entertaining to find ways to represent the two with types with relations that support the different semantics but with implementations that maximize code reuse between the two. The one sticking part, for me, is what to call the entity that defines the common aspects of the implementations. I've used "basis" in the "the underlying support or foundation for an idea, argument, or process" sense before. However, "basis" means something more specific in linear algebra so I don't really like it. Any ideas?
For instance:
In O'Caml, I played with an implementation like this:
type basisType = [`Point | `Vector];;
type 'a basis =
{ x : float; y : float; z : float; }
constraint 'a = [< basisType ];;
type point = [`Point] basis;;
type vector = [`Vector] basis;;
Notice vector and point were defined as ( ... )
Reply
As for what word to use, I think base is the right word. That's what the g++ STL implementation uses. In bits/stl_vector.h you'll see this:class vector : protected _Vector_base
I'm not literate in O'Caml, but I know what you mean. In this case I think we can just be mathematically pedantic to figure out how to do it: if an affine space is a vector space without an origin, then a vector is an affine point with some additional properties. Then we could just do
struct affine_point3 {
double data[3];
// ...
};
struct vector3 : public affine_point {};
double operator*(const vector3& a,
const vector3& b) {
return std::inner_product(a.data, a.data + 3,
b.data,
0.0);
}
// etc.
Of course, to be fully generic we don't want to limit ourselves to three-dimensional space; we should be prepared to deal with abstract points such as functions or sequences.
Reply
Reply
The rest of the affine transformations are nonlinear (in n dimensions). As I understand it, homogeneous coordinates are used in graphics because in n+1 dimensions, affine transformations are linear (allowing the magic of the OpenGL matrix stacks to work).
Reply
Reply
Leave a comment