Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

what does a vector-vector give?

What I'm trying to find out is what impact does a Vector3 minus another vector3 equals. What does this give specifically.

1 answer

✓ Accepted answer

Vectors are a general concept from linear algebra.

A vector space V is a set[^1] of things that we call vectors.

Vector spaces are associated with a field[^2], usually the real numbers or complex numbers. These are usually called scalars and are number-like.

[^1]: A set is an unordered collection. Sets form the basis of almost all mathematics.

[^2]: A field is a "nonzero commutative division ring", meaning it has "nice" addition, subtraction, multiplication, and division. "Nice" meaning multiplication/division distribute over addition; addition/subtraction and multiplication/division are inverses; addition is commutative and associative; and multiplication is commutative and associative.

There are two operations defined on vector spaces:

  • For vectors a and b in vector space V, a + b is a vector in V
  • For vector v in V and c a scalar, c * v is a vector in V.
    • in math, the * is often / usually omitted: cv or c v.
    • Note: rigorous mathematics always puts the scalar on the left. Thus v c (if v is a vector and c is a scalar) is invalid when being rigorous -- but most implementations/mathematicians won't care

These operations have to satisfy these properties:

  • Addition is commutative: a + b = b + a
  • Addition is associative: a + (b + c) = (a + b) + c
  • Scalar multiplication plays nice (compatible): a * (b * v) = (a * b) * v = b * (a * v) and 1 * v = v
  • Multiplication distributes, both ways: a * (u + v) = a * u + a * v and (a + b) * u = a * u + b * v

These are two more important properties of vector spaces:

  • There exists a 0 element in V: 0 + v = v for all v in V
    • NOTE: This 0 is NOT the number 0. It's usually written bold to differentiate it.
  • There exists an inverse for v, called -v, such that v + (-v) = 0

This final property is what gives us u - v = u + (-v)

TL;DR: Vectors are like numbers, except you can only

  • add them together
  • subtract them
  • make them bigger/smaller (but not multiply two together)

Okay, so what does this mean?

In practice, you don't deal with abstract objects called vectors. You deal with a specific type of object that has these properties[^3], like Vector3s in ROBLOX.

Vectors inherently describe change in value -- instead of thinking of 0 as a particular place, think of it as a description of "when I'm here... 0 is still here". In particular, me + 0 is still me.

So if someone is a bit to the right of me, say, 5 studs... They happen to be at them = me + Vector3.new(5, 0, 0). How would I have figured out where they were just given me and them? It's simple algebra!

-- NOTE: NOT LUA
-- Psuedo math/lua
them = me + Vector3.new(5, 0, 0)
-- subtract `me` from both sides:
them - me = me + Vector3.new(5, 0, 0) - me
them - me =  Vector3.new(5, 0, 0) + me - me
them - me = Vector3.new(5, 0, 0)

Thus when them and me are positions, them - me is the displacement from me to them (you can think of this more easily with numbers. If me = 5 and them = 9, how do I get from me to them? I add 4 -- 9 - 5 = 4.)

For Vector3s, you just subtract the corresponding components -- this is obvious from the necessary properties of - and given that addition just adds the corresponding components.

[^3]:Ex.: prove that Vector3s satisfy all the above properties

This discussion is preserved as it was. New answers, comments, and votes are closed.