Author Topic: Vector Math  (Read 1595 times)

Hey guys, this is a math-y question. I just left Algebra I, so I'm trying to wrap my head around vectors and vector math. A vector has magnitude (length) and direction. I get vector addition, but vector subtraction confuses me.

So basically, you're reversing the magnitude of the thing you're subtracting (b) and then doing the head-to-tail thing like in vector addition and you create your solution.
But this has me confused, since apparently the position of objects in space is also a vector. Even though it doesn't have magnitude OR direction? How can a point in space have direction? So, how can it be a vector? Also, a way to get the direction from one object to another is vectorSub(%pointA, %pointB);. How does this work, if they're points? You can't inverse a vector if it doesn't have magnitude????? Lets say %pointA and %pointB are two player's positions. How the hell does that work?

A point in space usually isn't thought of as a vector, though technically it is one with respect to the origin point "0 0 0".

What you're referring to with vector subtraction is the formula for creating a vector from one point to another, "final minus initial." Take the coordinates of the destination point, and subtract from it the position you start from, and it will give you a vector. If you start at the initial point, and apply that vector, you'll end up at the final point.

That diagram doesn't represent this process well, since vector b is already shown with respect to vector a. Consider this one:

Add b to a-b, and you get a, intuitively enough.
« Last Edit: August 13, 2015, 02:58:36 AM by -Jetz- »

I think you're misunderstanding how every point in space can be seen as a vector

if you have a point (5, 3, 6), you can represent it as a vector (5, 3, 6) from the origin (0, 0, 0)
a point on it's own doesn't have a direction, if you're claiming it's a vector it's often with respect to something, whatever or wherever that may be (either the origin or some other point way out somewhere)
and I do often see points in space as vectors, unlike what jetz says
it really depends on the context

but yeah, if you're subtracting vector B from vector A, just adding the inverse of B works well

The main difference between math class and torque is that yo  would have been taught a 2d coordinate system in class, whereas torque is 3d

In torque, a vector is any figure represented as "x y z" whether it be a position, velocity, distance, etc. As others have said, a point can be considered a vector from the origin
« Last Edit: August 13, 2015, 03:24:50 PM by Headcrab Zombie »

Torque treats all things as strictly untyped, which causes some interesting happy fun times.

All positions can be treated as vectors.
Both positions and vectors are represented as strings.
All strings can be treated as numbers.
All numbers can be treated as objects.
Therefore, any given position might potentially correspond to an object.

%obj.getPosition().delete();

%obj.getPosition().delete();
That's interesting.

I got the class name of the position and it returned it as a particle data.

what if you dump a position?
I thought it would just be a string/error because "5 5 5" doesn't relate to an object ID

Yeah, it's weird. I have dumped the getPosition() too, it returns the particle data, it even has a name known as "PlayerFoamDropletsParticle".

It's just odd that it returns a vector, but when you try to go into detail with getPosition(), it returns a datablock. Not sure about other types of objects that use getPosition().

It has to do with the way Torque casts strings to numbers.
It takes any digitis it finds, stopping after the first non-numerical character.
So "123 536 767" becomes "123" and then you're just calling methods on whatever object 123 is

oh, so it's less finding something at that position and using it, and more just trying to convert it to an object ID

It's also worth noting that when using a number as an object pointer, any non-integer number is rounded either down or towards zero, but since object IDs are strictly nonnegative it would be difficult to test which.


12345.67.delete();   // Deletes whatever object 12345 currently is.

is that (12345.67).delete();?
wouldn't 12345.67.delete(); try to delete a variable 67 of object 12345?

but since object IDs are strictly nonnegative it would be difficult to test which.
Or it's just
stopping after the first non-numerical character.

wouldn't 12345.67.delete(); try to delete a variable 67 of object 12345?
No, because identifier names can not begin with a number

is that (12345.67).delete();?
wouldn't 12345.67.delete(); try to delete a variable 67 of object 12345?

12345.67.delete(); deletes the object referenced by "12345.67", which is actually rounded either down or towards zero.

Or it's just stopping after the first non-numerical character.

Which would include the decimal portion:
echo("12345.67" + 3);