|
Could somebody help me understand this? Vectors (in physics) have a magnitude and direction and an x and y component right? But Vector3s in Roblox only have an x, y and z value, not a direction/magnitude. However a ray has an origin, direction, magnitude etc. So shouldn't a Ray be a Vector? I don't know why Vector3s are even called vectors in the first place. Please correct me if I'm wrong. |
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
Vector3's have a magnitude and direction |
|
soutenuJoin Date: 2011-12-09 Post Count: 1021 |
Vector3.magnitude
Vector3.unit |
|
|
Rays originate from my ### ##### and it has very large magnitude |
|
|
how do vector3s have magnitude, aren't they just a fixed point in space? |
|
|
A mathematical "ray" is a line that has an origin but no end (and thus is usually drawn like an arrow toward the non-ending direction).
But you need two vectors to describe a ray. The first is its position (i.e. it's origin). The second is a vector that describes its direction (typically a normalized/unit vector). Therefore, a Ray on ROBLOX consists of two Vector3s: one to tell you where it begins, and one to describe its direction.
Caveat: The "Direction" vector for Rays in ROBLOX aren't necessarily normalized, and thus can actually act more-so as mathematical "lines". Typically you would use a non-normalized ray for ray-casting a specific distance. IMO, this is a design flaw in ROBLOX. Instead, ROBLOX should have added a parameter in the raycasting API to denote distance and not rely on an improperly-formatted ray.
-----------
A vector3 by itself represents whatever you want. It is typically used to represent a position in 3D space, but is also often used to represent direction within 3D space in its normalized (i.e. unit) form.
Here's a ray that is positioned at 10, 30, 50, and points directly upward:
ray = Ray.new( Vector3.new(10, 30, 50), Vector3.new(0, 1, 0) ) |
|
|
The magnitude of a Vector3 is simply the pythagorean theorem. In other words, the distance formula, except finding the distance from the origin (0, 0, 0).
vector magnitude = sqrt(x ^2 + y ^ 2 + z ^ 2) |
|
TunicusJoin Date: 2013-02-16 Post Count: 3165 |
Side note, I've already wondered how magnitude multiplication respects the laws of algebra and I just now decided to prove it
so
sqrt((mx)^2 + (my)^2) = sqrt(m(x^2 + y^2))
sqrt(m^2 * x^2 + m^2 * y^2) = m * sqrt((x^2 + y^2))
sqrt(m^2(x^2 + y^2)) = m * sqrt((x^2 + y^2))
m * sqrt(x^2 + y^2) = m * sqrt(x^2 + y^2)
really this isn't a property unique to squares or two terms but i just thought it was interesting
|
|
TunicusJoin Date: 2013-02-16 Post Count: 3165 |
top equation should be
sqrt((mx)^2 + (my)^2) = m * sqrt(x^2 + y^2)
woops |
|
|
oh hi crazyman, so a vector3's magnitude is the distance from the origin (0, 0, 0)? and it can also be a direction in the form of a unit vector? But one vector3 on its own can't represent/have a magnitude and a direction, so therefore its a scalar? I'm sorry if I'm not making any sense, I might have the wrong understanding of a vector3. |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
It can have both a magnitude and direction.
A vector can be represented as both magnitude and direction by:
Vector = magnitude*direction
e.g. Vector3.new(5,4,7) == Vector3.new(5,4,7).magnitude*Vector3.new(5,4,7).Unit
Explanation:
This works because imagine drawing a line in 3D space from the origin to 5,4,7...
The .Unit version of that line is that same line in the same direction but with length 1 from the origin.
The .magnitude of that line IS the length of that line.
So the reason why the == works is because we multiply the unit vector (with length 1) by it's length which now results in a line with the same direction as 5,4,7 and now the same length because we multiplied it to be 1*(length of 5,4,7) long.
|
|
|
Thanks that makes a lot of sense, vector3s are basically lines starting from the origin, and it's magnitude is the distance from the origin and its direction is 1/itself (a unit vector). Always thought they were only just coordinates, thanks a lot guys. |
|
QuasiduckJoin Date: 2008-09-28 Post Count: 2437 |
Also, vectors can have any number of dimensions.
They can be one-dimensional, two-dimensional, three-dimensional, four-dimensional, etc.
Vector3 is just a three-dimensional vector.
You are probably used to doing physics with 1-dimensional vectors...
(e.g. Defining the positive direction of a falling ball)
As the ball can only fall/ or go up. That is 1 dimensional.
In 2-dimensions, projectile motion from physics. Stuff can now move up-down, left-right.
And one final note, instead of thinking as a vector as the distance from the origin.
It's better and more intuitive to think of it intrinsically as "the length of that vector" because if you draw a line from (0,0,0) to the tip of the arrow where the vector points... (i.e. it's coordinates)... the length of that line IS the distance from the origin.
|
|