How to think about CFrames

If every wiki article was like this do you know how smart I would be, and how much better at coding I would be? I’ve been pondering this for YEARS and in the first few damn lines he’s explained it to me… Literally, not exaggerating, for years…

w1k1 pl0x?

2 Likes

If I could build ROBLOX from scratch, I would rewrite the components function to return the matrix in inverse order so that you could get it in a way that makes sense.

--How I would do it:
Px,Py,Pz,   Xx,Xy,Xz,   Yx,Yy,Yz,   Zx,Zy,Zz   =   SomeCFrame:components()

Also, if I were to define the z axis as the forward and backward axis, I would use left hand rule instead of right hand rule, such that z would get more positive as you go forward. This, by the way, would also make Euler angles make a little more sense (The x angle would no longer be negative).

If I could edit ROBLOX code, I would add functions to CFrame such that when you said:

SomeCFrame.Right
SomeCFrame.Top
SomeCFrame.Back

it would return you Vector3s of the CFrame’s directions.

I would also add better support for axis angle rotations and quaternions. I would also have an interpolate function for CFrames.

There’s a lot of stuff I would do differently that I feel would make more sense.

Always been annoyed by eulerangles, that I atleast had a little understanding of, that and the inversed Z axis.

I don’t understand CFrames at all, so here’s my feedback to your post.

You didn’t explain what a vector is. Something with both magnitude and direction? Maybe show examples of 2-dimensional vectors and 3-dimensional vectors in ROBLOX (e.g. Vector2.new(x, y), Vector3.new(x, y, z)).

[quote]A CFrame actually contains three more of these lookVectors, except instead of pointing in the forward direction, they point to the right, top and back of the CFrame
It’s confusing to say CFrames have 3 more lookVectors when they aren’t called lookVectors. Why is the positional vector called lookVector anyway?[/quote]
I still don’t understand, given the right, top, and back vectors, how can you “visualize” which direction a CFrame is pointing in. Perhaps show a diagram with an example CFrame and how the three directional vectors determine the rotation?

As for your vector mishap, have you never set the position of a part before? This definitely does not fit in the CFrame post I made, (which is for people who already understand how to use CFrame a little, but not completely, and don’t understand how it works), so I’ll tell you directly.

A vector is a number. Just as numbers can be used to represent all kinds of things, so too can vectors.
a vector contains any amount of numbers. A 3D vector, known as Vector3 in ROBLOX, contains 3 numbers. A 2D vector contains 2 numbers.

We live in a 3D world, and ROBLOX is a 3D game world. This means that you can move to the left and right, up and down, and forward and backward, which are three directions (3 dimensions). We can use 3D vectors to represent positions, as well as directions in 3D space.

When it comes to vector positions, I draw those as points (see the point, Position Vector, in the drawing above), and I draw directions as arrows (see Right, Top and Back Vectors in drawing above).

Directions are generally represented as unit vectors. A unit vector is a vector with a length of one. For example, the vector, <1,0,0> has a length of 1 because if you were to take a ruler and measure from <0,0,0> to <1,0,0>, the length on the ruler would say 1.

Uh, that’s all, really. What do you do if you don’t build or code, though?

1 Like

The pictures all loaded, but I wasn’t able to make sense of them, knowing nothing of CFrames.

2 Likes

I just put a tremendous amount (a full hour) of effort into trying to come up with the perfect way to explain vectors from the ground up, and you don’t even recognize me for it. If you want to learn CFrames, or really do anything, you can’t laze around and ask people to give you answers to everything. You need to take an active stance in your learning.

Also, keep in mind

1 Like

I appreciate that you made this guide to understanding CFrames. I understand that it’s not targeted at users who have no experience with CFrames, but I am one of those users. I tried to ask you specific questions about what I don’t understand so you could clarify.

Edit: I just noticed you posted some new content in reply to my previous message. I thought you had just posted a quote of the original post. Thanks!

1 Like

“A vector is a number.”

But, but, but… My physics teacher said a vector is a number with a direction, a scalar is just a number.

1 Like

[quote] “A vector is a number.”

But, but, but… My physics teacher said a vector is a number with a direction, a scalar is just a number. [/quote]

I’m pretty sure he said direction and length, as length isn’t really accessable, til you calculate it.

And unlike scalar, vector is several numbers, nothing more.

1 Like

[quote] “A vector is a number.”

But, but, but… My physics teacher said a vector is a number with a direction, a scalar is just a number. [/quote]

A vector is a number that represents a direction.

Vector3 is 3 numbers that represent a direction.

2 Likes

[quote] “A vector is a number.”

But, but, but… My physics teacher said a vector is a number with a direction, a scalar is just a number. [/quote]

A vector is a number that represents a direction.

Vector3 is 3 numbers that represent a direction.[/quote]

A 3D vector is a number that is composed with three elements. Kind of how a quaternion is a single number that represents an orientation.

1 Like

Quaternions next please!

Welcome to the new wiki writer!
We’re all waiting for more articles :stuck_out_tongue:

Quaernions are fairly easy to understand once you’ve learned them… Basically works just like e^(i theta) except in 3D, but it’s exceedingly hard to explain.

I guess I could start in terms of 2D rotations using imaginary numbers, skip all of the proofs, and keep it all conceptual.

I might want to do one on Vector stuff first, like dot and cross product, as well as a useful way to think about vectors.
…Did you know that dot and cross product come from quaternions?

2 Likes

[quote]
…Did you know that dot and cross product come from quaternions? [/quote]

No, no I did not.

The dot product and the cross product have their origins in physics. You might know that work is equal to force times distance when the force and the distance traveled are parallel. The dot product is an extension of this to cases where force and distance are not parallel. Essentially it is the same as taking the parallel component of the force being applied and then multiplying it by the distance (or vice versa).

There is an analogy for the cross product with torque. If you push directly down against a balanced beam, you are pushing perpendicular to it. Note that pushing directly perpendicular to the beam gives maximum leverage with respect to the input force. This can be explained in part by the fact that |sin(theta)| = 1 when theta is a right angle (i.e. 90 degrees or -90 degrees). Intuitively, that the cross product is always perpendicular to the operand vectors can be visualized by the analogy of turning a wrench.
It is also indeed true that the magnitude of the cross product is equal to the area of the parallelogram formed by the two vectors. This is a natural consequence of the fact that the area of a parallelogram is the length of the base times the height, because if one vector is taken to be the base, then the other vector times the sine of the angle is the relative height of that vector.

As a programmer, I find myself using the dot product much more often than the cross product. For an example of the usage of the dot product, suppose I want to find out if a point lies within a polygon (in the 2-dimensional case, for simplicity, but this is also applicable to any number of dimensions). This is very straightforward with dot products (at least for convex polygons) as one is able to gather information about the point relative to each edge of the polygon.
However the cross product is also very nice as it allows you to trivially compute the surface normal of a polygon in 3D space given two of its edges.

You’re not wrong. Though the history doesn’t go all the way back. I also feel as though your description is a bit limited.

Dot and cross product have their origins in quaternions, though Quaternions DID play a lot into physics. Hamilton described quaternions as the product of two vectors. In other words, q = a dot b + i (a cross b)
Where i is <sqrt(-1), sqrt(-1), sqrt(-1)>
and where multiplication with i is component-wise.

My definition is quite visual. Once I came up with this definition for dot product, it has been the only definition I have ever needed. I have actually changed my understanding of everything else to fit this definition, lol. It’s really useful.

Dot product is especially useful when you have at least one unit vector, u and another vector p, where u dot p returns the distance p travels in the direction of u.

Cross product, the way it’s defined with two vectors, is more of a hack for 3D. Very valid, just way less useful than dot product, and in many cases, something which can be entirely replaced with dot product in cases such as:
a cross b cross c = something I don’t remember
and
||a cross b|| = sqrt((a dot a)(b dot b) - (a dot b)(a dot b))

I’ve left stuff out. This is more in addition to your explanation.

1 Like

Limited, yes, but I veered away from quaternions intentionally. For those who haven’t worked extensively with vectors, quaternions are a very confusing subject. I am not unfamiliar with their history–in fact, I was under the impression that I was the one who told you the dot and cross products arise naturally from quaternion algebra.

I disagree with your description of quaternions. Strictly speaking, the square root of -1 is not a unique number under the quaternions. In the case of the complex numbers, the two solutions to x^2 = -1 are +i and -i. But when you introduce the other two basis elements (j and k), then there are an infinitude of solutions to the equation x^2 = -1, as any number living on the unit sphere of basis (i, j, k) satisfies that relation.
To arrive at the quaternions it is necessary to adjoin elements such as j and k that satisfy Hamilton’s identity i^2 = j^2 = k^2 = ijk = -1. This equation encodes the vital information that i, j, and k are mutually orthogonal. Such numbers do not exist in the complex number field.

Moreover you are incorrect about the product of two vectors–for vectors a, b, the Hamilton product ab is equal to -(a dot b) + (a cross b). The quaternion was traditionally defined by Hamilton and his successors as the quotient of two vectors so as to represent a transformation between one another–a rotation combined with a change of length. The product q = (1/b)a is equal to (1/magnitude(b))^2 * ((a dot b) + (a cross b)), so that bq = a.

–Morpheus

Btw, been wanting to get into quaternions for a while because of interpolation on matrices natively doesn’t yield very good results, but my math book doesn’t go into quaternions, so I never took the step (also, tbh, a little frightened by them, and the strange voodoo talk people give when talking about them), I’d love for you to write a tutorial on them :smiley: