@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
40 lines • 1.61 kB
JavaScript
import { Clamp } from "../Maths/math.scalar.functions.js";
import { Quaternion, Vector3 } from "../Maths/math.vector.js";
import { Vector3Dot, Vector4Dot } from "../Maths/math.vector.functions.js";
// *** NOTE ***
// These functions should ideally go in math.vector.functions.ts, but they require math.vector.ts to
// be imported which is big. To avoid the larger bundle size, they are kept inside flow graph for now.
/**
* Returns the angle in radians between two quaternions
* @param q1 defines the first quaternion
* @param q2 defines the second quaternion
* @returns the angle in radians between the two quaternions
*/
export function GetAngleBetweenQuaternions(q1, q2) {
return Math.acos(Clamp(Vector4Dot(q1, q2), -1, 1)) * 2;
}
/**
* Creates a quaternion from two direction vectors
* @param a defines the first direction vector
* @param b defines the second direction vector
* @returns the target quaternion
*/
export function GetQuaternionFromDirections(a, b) {
const result = new Quaternion();
GetQuaternionFromDirectionsToRef(a, b, result);
return result;
}
/**
* Creates a quaternion from two direction vectors
* @param a defines the first direction vector
* @param b defines the second direction vector
* @param result defines the target quaternion
* @returns the target quaternion
*/
export function GetQuaternionFromDirectionsToRef(a, b, result) {
const axis = Vector3.Cross(a, b);
const angle = Math.acos(Clamp(Vector3Dot(a, b), -1, 1));
Quaternion.RotationAxisToRef(axis, angle, result);
return result;
}
//# sourceMappingURL=flowGraphMath.js.map