Page 1 of 2
Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 2:11 pm
by XianForce
Well, a while back I made a little SDL Framework to make development faster. It has it's own Rectangle class and Point class. Lately I've been thinking about adding onto it, and add some more useful classes such as 2D vectors, but thinking about it, I'd probably use a vector with an x,y component over a point, and even in places where I'm tracking the position of something, I usually opt to use a Rectangle over a point, so I can specify a Height and width as well.
So my question to anyone who actually reads this is, is it pointless (no pun intended...) to have a point class? Should it's 'job' be taken care of by a vector/rect? Or should the vector only have a magnitude, and not contain it's x,y? Should an empty rect act as a point?
At the moment, my Point class is 'useful' (I got most of it from Focus On SDL), but I haven't personally found use for it, but I hesitate to remove it, because I might find use for it later haha.
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 2:56 pm
by K-Bal
A point is defined by (x,y).
A vector is defined by (x,y).
The difference is .... drum roll .... the name
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 2:59 pm
by MrDeathNote
K-Bal wrote:A point is defined by (x,y).
A vector is defined by (x,y).
The difference is .... drum roll .... the name
^This
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 3:01 pm
by XianForce
K-Bal wrote:A point is defined by (x,y).
A vector is defined by (x,y).
The difference is .... drum roll .... the name
Errr... Vectors are defined by magnitude which can be derived from x,y. Two vectors with a different position, yet same magnitude are the same (thanks to qp for that little tidbit haha).
Uhh but my question is, whether any of you, have a separate point class, or just use a vector with x,y compenents or perhaps a rectangle instead of a point.
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 3:25 pm
by K-Bal
XianForce wrote:Two vectors with a different position, yet same magnitude are the same.
You are talking about rays. How could two things with a diverging attribute be the same?
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 4:18 pm
by XianForce
K-Bal wrote:XianForce wrote:Two vectors with a different position, yet same magnitude are the same.
You are talking about rays. How could two things with a diverging attribute be the same?
>.> This is going no where.
In either case, it's not answering the question I asked >.>
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 4:33 pm
by qpHalcy0n
Lord no. The differences between points and vectors are HUGE.
As I've said, they're represented the same way. However the operations performed between then *ARE NOT* the same. It's important to abstract them because of what they mean, especially in terms of graphics.
Again, Points have location. No direction.
Vectors have direction, but no absolute location. (This has different meaning given context).
A vector MUST contain a dx and a dy otherwise there *IS* no definition for magnitude. It's a case where on the outside it looks the same, but on the inside they do wildly different things and represent completely different ideas.
Point - Point = Vector
Vector - Vector = Vector
Vector - Point = Point
Point + Point = Vector
Vector + Vector = Vector
Vector + Point = Point
Vectors can be normalized, projected as a LINE, they have different homogenization characteristics....the list goes on and on and on.
I think what's happening here is that you've merely scratched the very first atoms of the surface of the mathematics behind computer graphics :] Since you don't understand the implications yet you're going to try to make a hasty decision in terms of a design choice. Rest assured, there is a difference and you WILL see it later. It becomes HUGE later. If you mix them up you're in for some big fat headaches.
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 4:52 pm
by K-Bal
A vector is an element of a vector space, a n-dimensional tuple with members of a certain field. The operations you define on them is up to you and wether you call it point, position or ballaluba.
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 5:01 pm
by XianForce
qpHalcy0n wrote:Lord no. The differences between points and vectors are HUGE.
As I've said, they're represented the same way. However the operations performed between then *ARE NOT* the same. It's important to abstract them because of what they mean, especially in terms of graphics.
Again, Points have location. No direction.
Vectors have direction, but no absolute location. (This has different meaning given context).
A vector MUST contain a dx and a dy otherwise there *IS* no definition for magnitude. It's a case where on the outside it looks the same, but on the inside they do wildly different things and represent completely different ideas.
Point - Point = Vector
Vector - Vector = Vector
Vector - Point = Point
Point + Point = Vector
Vector + Vector = Vector
Vector + Point = Point
Vectors can be normalized, projected as a LINE, they have different homogenization characteristics....the list goes on and on and on.
I think what's happening here is that you've merely scratched the very first atoms of the surface of the mathematics behind computer graphics :] Since you don't understand the implications yet you're going to try to make a hasty decision in terms of a design choice. Rest assured, there is a difference and you WILL see it later. It becomes HUGE later. If you mix them up you're in for some big fat headaches.
Thank you, that's exactly what I wanted to hear haha.
So I'll just leave them there, and when I get to a place where I need them, I'll use them.
Thanks, once again!
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 5:08 pm
by qpHalcy0n
...that is correct, but the key here is "in VECTOR space".
There are multiple definitions of a vector.
This particular definition demands that the definition be in a "vector space" which is "defined by vectors". That is that the elements can be scaled added and multiplied together. This annihilates the definition of a point, because if you multiply a point by a scalar, it no longer retains definition. Eg: it is no longer the same point. So a point is an absolute idea in a cartesian space, but in a vector space point's are defined as scalars of vectors. This is a parallel, but not a definition because in this space the definition of a point DEPENDS ON a vector in the space.
Another definition is that a vector is "a directed quantity". This means that it has direction and length. A point has no length.
Many programmers choose not to abstract these two ideas away for simplicity of code and size reductions, but rest assured you MUST know how each is being used because there is most definitely a profound difference between them.
Please do not listen to those that say the only difference is name, you'll be setting yourself up for a misconception of this form of math. There are numerous parallels and similarities between them, but they are not the same....at all.
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 5:13 pm
by XianForce
qpHalcy0n wrote:...that is correct, but the key here is "in VECTOR space".
There are multiple definitions of a vector.
This particular definition demands that the definition be in a "vector space" which is "defined by vectors". That is that the elements can be scaled added and multiplied together. This annihilates the definition of a point, because if you multiply a point by a scalar, it no longer retains definition. Eg: it is no longer the same point. So a point is an absolute idea in a cartesian space, but in a vector space point's are defined as scalars of vectors. This is a parallel, but not a definition because in this space the definition of a point DEPENDS ON a vector in the space.
Another definition is that a vector is "a directed quantity". This means that it has direction and length. A point has no length.
Many programmers choose not to abstract these two ideas away for simplicity of code and size reductions, but rest assured you MUST know how each is being used because there is most definitely a profound difference between them.
Please do not listen to those that say the only difference is name, you'll be setting yourself up for a misconception of this form of math. There are numerous parallels and similarities between them, but they are not the same....at all.
well mathematically I know they are different. But I was speaking specific to programming, but you cleared it all up. Much appreciated =D
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 5:33 pm
by K-Bal
The mathematician defines a bunch of numbers as a vector. He does not interpret it, which is what you are doing. What you say is correct if you would try to distinguish between positions and directions.
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 5:48 pm
by qpHalcy0n
In theoretical mathematics this is the case. However, analytic geometry is definitely a discrete form of math for which there are most certainly definitions, in which case the definition of the vector becomes that which was described at length in the post. In terms of computer graphics which works w/ discrete surfaces, "a collection of numbers" means nothing. It means something given definition.
Thusly "A collection of numbers" called a "point" means one thing.
"A collection of numbers" called a "vector" means another.
"A collection of numbers" represented linearly can be called a matrix, which is a complete linear system.
All different concepts.
This is true for most forms of applied mathematics.
Re: Points/Vectors/Rectangles
Posted: Sun Feb 28, 2010 6:07 pm
by RyanPridgeon
In mathematics & physics in education I've always been taught clearly from the start that there are DIRECTION vectors, and POSITION vectors, and that they should definitely not always be treated the same.
Re: Points/Vectors/Rectangles
Posted: Mon Mar 01, 2010 8:26 am
by Falco Girgis
I'm going to flat out answer your question and tell you
exactly what to do. Yes, there is a lot of confusion as to how your R-brain should interpret a vector--and this is something that you need to get good at, because then you can interpret linear-algebra problems effectively in terms of vectors--but you kind of need to get started first. I think this is an interesting topic with good questions that somebody never really introduced to the mathematical structure of a "vector" would find pretty interesting.
XianForce wrote:So my question to anyone who actually reads this is, is it pointless (no pun intended...) to have a point class? Should it's 'job' be taken care of by a vector/rect? Or should the vector only have a magnitude, and not contain it's x,y? Should an empty rect act as a point?
You will NEVER need to create a separate "point" class from a vector. A Vector2 can be used in your program to represent a 2 dimensional point, always. As a vector can be thought of (in one context) as the distance from one point to another, a "position vector" or just "point" may be thought of geometrically as the displacement of that point from the origin. And voila, your Vector2 becomes your 2D point.
XianForce wrote:Or should the vector only have a magnitude, and not contain it's x,y?
This is incorrect. A vector has a
direction and a
magnitude. A vector cannot be represented as a one dimensional scalar (magnitude), because you're losing the direction of the vector.
A vector should always be represented as <x,y>. You can have a member method that
derives the magnitude of a given vector for when this is needed or convenient (using the distance formula/Pythagorean's theorem).