May seem like a stupid question but is it?
I’ve already dug through google and unity forums but couldn’t find a clear answer. So what is the real difference of Slerp and Lerp?
SLERP is a spherical linear interpolation. The interpolation is mapped as though on a quarter segment of a circle so you get the slow out and slow in effect. The distant between each step is not equidistant.
LERP is a linear interpolation so that the distant between each step is equal across the entire interpolation.
A quick google search would have answered this for you. I know you say you dug through google but there are dozens of results when I enter either “SLERP” or “spherical LERP” that describes the difference.
Hi…Quaternion.Lerp
static function Lerp (from : Quaternion, to : Quaternion, t : float) : Quaternion
Description
Interpolates from towards to by t and normalizes the result afterwards.
This is faster than Slerp but looks worse if the rotations are far apart.
javascript code is here…
// Interpolates rotation between the rotations
// of from and to.
// (Choose from and to not to be the same as
// the object you attach this script to)
var from : Transform;
var to : Transform;
var speed = 0.1;
function Update () {
transform.rotation =
Quaternion.Lerp (from.rotation, to.rotation, Time.time * speed);
}
Quaternion.Slerp
static function Slerp (from : Quaternion, to : Quaternion, t : float) : Quaternion
Description
Spherically interpolates from towards to by t.
javascript code is here…
// Interpolates rotation between the rotations
// of from and to.
// (Choose from and to not to be the same as
// the object you attach this script to)
var from : Transform;
var to : Transform;
var speed = 0.1;
function Update () {
transform.rotation =
Quaternion.Slerp (from.rotation, to.rotation, Time.time * speed);
}
and you can search there most of the methods/functions/classes/etc.
To answer your question, the differences are performance and accuracy. Slerp interpolates two Quats accurately and precisely which requires more power, Lerp interpolates two quats unevenly. Basically if your in doubt use slerp and then if your game runs slower than you like try changing some Slerp calls to Lerp ideally where its not a big deal.
But really you should just try each and see which gets the job done better, giving a little slack/advantage to lerp because it faster.
I know this is an old thread but this video may be useful for future readers.
Lerp = blue point
Slerp = white point.
OJ - This really helped, thanks!:o
I don’t get this, I thought quaternions were rotations. How do these moving points (Vector3) represent rotations(Vector4)?
The components of a quaternion vector are simply the components of a 4D complex number…
Quaternion Q = <a, b, c, d>
Q is a complex number of the form:
Q = a + ib + jc + k*d; Where i, j, and k follow the various rules of quaternion arithmetic discovered by William Rowan Hamilton.
Position in complex space can represent both scale and orientation in real space. Understanding precisely how a position in 4D complex hyperspace geometrically can represent real orientation in 3D real space is extremely difficult. But, you can begin to understand it if you know how 2D complex numbers can be used to represent 2D rotation (and scale) in real space and why multiplying two 2D complex numbers together results in a 2D rotational transform. There are many good explanations of that on the web.
From my understanding the extra w parameter denotes the rotation.
None of the components of the quaternion vector represent an angle, although it may be possible to run across a case where changing one or two of the values results in the rotation you expected. The coordinate system that a quaternion represents is determined by combinations of all four components.
Given the unit quaternion q = (w,x,y,z), the equivalent left-handed (Post-Multiplied) 3×3 rotation matrix is:
Again, it’s a lot easier to understand how and why quaternions work if you first learn how and why 2D complex numbers can be used to compute 2D rotational transforms. The principles are much the same.
One of the best explanation videos I’ve ever seen in my life. Perfect and concise; thanks for posting this.
Best post ever!
Vector3’s are not “points” and Vector4’s are not “rotations”. And Quaternions are not any type of vector although I actually like to imagine them as unit vectors that know what their orientation is.
Vectors are arrows that represent a direction that is permanently tied to an amount. Like 4 pounds to the left or 3 meters down. The units are irrelevant.
Where vectors get confused with points is that they store the point of the arrow head. The tail is always “assumed” to be at the origin (x,y,z=0,0,0). Mostly we use 2D or 3D vectors. A Vector 4 is kind of a tool we use to get the job done. Technically a Vector4 is a 4D vector which is impossible to imagine unless you come from a 4D universe. We don’t use 4D vectors directly. Instead we shove 3D data into the 4D vector and then add another component. The reason we do this is generally to make the math come out right when working with the 4 by 4 matrices common in game math. (Which you never see in Unity, but that’s basically what a “transform” is and you know how common those are in Unity. Matrices are handled under the hood for you in Unity, but you still need a 4D vector to multiply it times a 4 by 4 matrix.)
Anyway, the 4D vector is probably x,y,z,w where x,y,z represents a 3D position or vector and w is an additional component that we use to make the math come out right which is usually 0 or 1.
Vectors are always 2 positions: the head which is stored in the Vector object and the tail which doesn’t need to be stored because ti’s always at the origin.
Quaternions are none of the above. That can be confusing for several reasons, including that Quaternions have 4 components, just like a 4D vector does. Because of that, you “could” store the 4 components of a Quaternion in the 4 components of a 4D vector, but that doesn’t mean they are related to one another.
All of the Quaternions used in game programming are a special type of quaternion called a “unit quaternion”. Their value equals one. By doing that, the quaternion value is forced onto a 3D sphere that is two units in diameter. Because the sphere is 3D, you’ve “forced” the quaternion to exist in 3D space with a hidden 4th dimension that makes every possible 3D orientation unique.
Quaternions are mind boggling. But it doesn’t matter. You should think of quaternions as “black boxes” that hold rotations. It doesn’t matter what happens inside the box. What matters is that you put a rotation/orientation in and you get the correct rotation/orientation out. And maybe it should be pointed out that we’re not talking about a rotation here as much as we are talking about an orientation. All 3 dimensions of rotation (pitch, yaw, roll) are stored simultaneously in the quaternion. If you combine two quaternions with multiplication the resulting quaternion will hold the final orientation after applying both rotations.
So, a quaternion can store the result of several orientation changes in one quaternion. This is basically the same for a rotational matrix. Quaternions and rotational matrices are used pretty much the same way, although I think rotational matrices are not commonly used externally in Unity (they’re probably all over the place under the hood in Unity).
But anyway, don’t get vectors, quaternions, and matrices confused. We sometimes use them together, but they are all 3 completely separate things.
Oh. And to answer your original question of “How do these points represent rotations?” LERP is interpolation. It’s just a percentage: “How far is it between point A and point B? 20%? 40%? 82%?” When “LERP’ing” between two numbers you are just multiplying the percentage. So, you say “give me a point that is 23% of the way between Point A and Point B.”
With simple interpolation you do this on a 1 dimensional number line. For game programming you’re probably going to use this at least in 2D if not 3D. So, you’re finding a point that is 23% of the way between two 2D points or two 3D points, for example. It’s called Linear intERPolation because the answers are all on a straight line.
SLERP is the same thing except you’re getting a percentage distance between two points on a circle or in 3D on a sphere.
LERP in not necessarily a rotational thing, since it’s on a straight line. A percentage distance between 2 points is not necessarily related to a rotation.
But when you DO interpolate between two rotational positions, you generally want to use SLERP because LERP is inaccurate. That’s because rotations happen on circles, not straight lines.
So, SLERP is mostly for rotations, and LERP is largely not for rotations. Both are just finding a percentage position between two points. LERP does it on a straight line. SLERP does it on a circle, which is more appropriate for rotations. But hey, if you get good results from LERP in a rotation, more power to ya. The very helpful video shows how both could be applied to an unknown position between two given positions on a circle. When you do the LERP or SLERP math, you will give two points and a percentage between them and receive an answer of a point that is that percentage between the two. But LERP is linear and SLERP is spherical.
Thank You! Thank You! Thank You!
You have truly enlightened me! I can’t say I understand all of it, but I now have a pretty good grasp of what all these things represent.
I dont know much about Quaternion.
But I think we should not try to understand Quaternion as an angle(or Radian).
The difference between Quaternion and Degree(or Radian) determines the usage of Slerp(Instead of Lerp).
For me this was from google so it’s good that these topics exist.
Best answer I think!
This post is the first one that came up on Google. Congrats on being a jerk though
you are the google search dude