Points/Vectors/Rectangles
Moderator: Coders of Rage
Points/Vectors/Rectangles
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.
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
A point is defined by (x,y).
A vector is defined by (x,y).
The difference is .... drum roll .... the name
A vector is defined by (x,y).
The difference is .... drum roll .... the name
- MrDeathNote
- ES Beta Backer
- Posts: 594
- Joined: Sun Oct 11, 2009 9:57 am
- Current Project: cocos2d-x project
- Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
- Programming Language of Choice: C/++
- Location: Belfast, Ireland
- Contact:
Re: Points/Vectors/Rectangles
^ThisK-Bal wrote:A point is defined by (x,y).
A vector is defined by (x,y).
The difference is .... drum roll .... the name
http://www.youtube.com/user/MrDeathNote1988
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
Re: Points/Vectors/Rectangles
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).K-Bal wrote:A point is defined by (x,y).
A vector is defined by (x,y).
The difference is .... drum roll .... the name
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
You are talking about rays. How could two things with a diverging attribute be the same?XianForce wrote:Two vectors with a different position, yet same magnitude are the same.
Re: Points/Vectors/Rectangles
>.> This is going no where.K-Bal wrote:You are talking about rays. How could two things with a diverging attribute be the same?XianForce wrote:Two vectors with a different position, yet same magnitude are the same.
In either case, it's not answering the question I asked >.>
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Points/Vectors/Rectangles
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.
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
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
Thank you, that's exactly what I wanted to hear haha.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.
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!
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Points/Vectors/Rectangles
...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.
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
well mathematically I know they are different. But I was speaking specific to programming, but you cleared it all up. Much appreciated =DqpHalcy0n 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.
Re: Points/Vectors/Rectangles
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.
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Points/Vectors/Rectangles
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.
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.
- RyanPridgeon
- Chaos Rift Maniac
- Posts: 447
- Joined: Sun Sep 21, 2008 1:34 pm
- Current Project: "Triangle"
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C/C++
- Location: UK
- Contact:
Re: Points/Vectors/Rectangles
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.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Points/Vectors/Rectangles
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.
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).
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: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?
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.XianForce wrote:Or should the vector only have a magnitude, and not contain it's x,y?
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).