Answers for "multiply quaternion by vector"
http://answers.unity.com/questions/186252/multiply-quaternion-by-vector.html
The latest answers for the question "multiply quaternion by vector"Answer by kubajs
http://answers.unity.com/answers/1565347/view.html
I know this is quite old post but I believe this visualisation might help a lot to those who are still struggling, just play with it a bit, it's intuitive.
I had similar problems with Quaternions and then hpjohn sent me his sample code (https://forum.unity.com/threads/compare-rotation-of-matrix-with-initial-direction.572440/#post-3811600) I played with a bit and added local rotations, now I can understand that much better:
using UnityEngine;
public class RotationTest : MonoBehaviour
{
Quaternion currentState;
private void Start()
{
//store initial state
currentState = Quaternion.identity;
}
private void Update()
{
//draw axes tripod in viewport for demo
Debug.DrawRay(Vector3.zero, currentState * Vector3.up, Color.green);
Debug.DrawRay(Vector3.zero, currentState * Vector3.right, Color.red);
Debug.DrawRay(Vector3.zero, currentState * Vector3.forward, Color.blue);
}
private void OnGUI()
{
RotateOnGlobalAxis();
RotateOnLocalAxis();
CompareCurrentPositionWithInitialState();
}
private void RotateOnGlobalAxis()
{
GUILayout.BeginArea(new Rect(100, 100, 200, 100));
if (GUILayout.Button("Rotate around global X"))
{
currentState = Quaternion.Euler(90, 0, 0) * currentState;
}
if (GUILayout.Button("Rotate around global Y"))
{
currentState = Quaternion.Euler(0, 90, 0) * currentState;
}
if (GUILayout.Button("Rotate around global Z"))
{
currentState = Quaternion.Euler(0, 0, 90) * currentState;
}
GUILayout.EndArea();
}
private void RotateOnLocalAxis()
{
GUILayout.BeginArea(new Rect(350, 100, 200, 100));
if (GUILayout.Button("Rotate around local X"))
{
currentState = currentState * Quaternion.Euler(90, 0, 0);
}
if (GUILayout.Button("Rotate around local Y"))
{
currentState = currentState * Quaternion.Euler(0, 90, 0);
}
if (GUILayout.Button("Rotate around local Z"))
{
currentState = currentState * Quaternion.Euler(0, 0, 90);
}
GUILayout.EndArea();
}
private void CompareCurrentPositionWithInitialState()
{
GUILayout.BeginArea(new Rect(225, 200, 200, 20));
if (GUILayout.Button("Check State"))
{
Vector3 currentUp = currentState * Vector3.up;
if (Vector3.Dot(currentUp, Vector3.up) > 0.9f)
{
Debug.Log("Current State has up pointing up");
}
else
{
Debug.Log("Current State has up pointing somewhere else");
}
}
GUILayout.EndArea();
}
}Tue, 23 Oct 2018 21:29:43 GMTkubajsAnswer by m16a
http://answers.unity.com/answers/666298/view.html
Hi, I had the same problem too. I figured out that notation `quaternion * vector` uses overloaded multiply operator which incapsulate mathematical multiplying `quaternion * vector * quaternion^(-1)` [similar question][1]
[1]: http://answers.unity3d.com/questions/372371/multiply-quaternion-by-vector3-how-is-done.htmlMon, 17 Mar 2014 18:18:37 GMTm16aAnswer by aldonaletto
http://answers.unity.com/answers/186261/view.html
In the quaternion world, multiplication is the way to apply the rotation to something - when you multiply quaternion by vector3, you're actually rotating the vector. For instance:
var rot = Quaternion.Euler(0, 45, 0); // rot = 45 degrees rotation around Y
var v45 = rot * Vector3.forward; // rotate vector forward 45 degrees around Y
I didn't understand your question about point rotation - maybe a typo, but what we can read is a _quaternion *** vector3 * Quaternion.Inverse(quaternion)_, what makes no sense (this sequence isn't even allowed: Vector3 must be at the right of the quaternions).<br>
In practice, multiplying a quaternion by a point rotates this point relative to the origin (0,0,0).<br>
Finally, Quaternion.Inverse(quaternion) returns the inverse rotation (same rotation, but to the opposite side).Tue, 15 Nov 2011 10:01:27 GMTaldonaletto