|
|
@ -1,10 +1,34 @@ |
|
|
module MathNet.Numerics.Quaternion |
|
|
// <copyright file="Quaternion.fs" company="Math.NET"> |
|
|
|
|
|
// Math.NET Numerics, part of the Math.NET Project |
|
|
|
|
|
// http://numerics.mathdotnet.com |
|
|
|
|
|
// http://github.com/mathnet/mathnet-numerics |
|
|
|
|
|
// http://mathnetnumerics.codeplex.com |
|
|
|
|
|
// |
|
|
|
|
|
// Copyright (c) 2009-2016 Math.NET |
|
|
|
|
|
// |
|
|
|
|
|
// Permission is hereby granted, free of charge, to any person |
|
|
|
|
|
// obtaining a copy of this software and associated documentation |
|
|
|
|
|
// files (the "Software"), to deal in the Software without |
|
|
|
|
|
// restriction, including without limitation the rights to use, |
|
|
|
|
|
// copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
|
|
|
|
// copies of the Software, and to permit persons to whom the |
|
|
|
|
|
// Software is furnished to do so, subject to the following |
|
|
|
|
|
// conditions: |
|
|
|
|
|
// |
|
|
|
|
|
// The above copyright notice and this permission notice shall be |
|
|
|
|
|
// included in all copies or substantial portions of the Software. |
|
|
|
|
|
// |
|
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
|
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
|
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
|
|
|
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
|
|
|
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
|
|
|
|
|
// OTHER DEALINGS IN THE SOFTWARE. |
|
|
|
|
|
// </copyright> |
|
|
|
|
|
|
|
|
//Reference: |
|
|
namespace MathNet.Numerics |
|
|
//http://www.astro.rug.nl/software/kapteyn/_downloads/attitude.pdf |
|
|
|
|
|
//http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html |
|
|
|
|
|
//http://www.mathworks.com/help/aeroblks/quaterniondivision.html |
|
|
|
|
|
//https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#The_conjugation_operation |
|
|
|
|
|
|
|
|
|
|
|
type Quaternion = |
|
|
type Quaternion = |
|
|
{ |
|
|
{ |
|
|
@ -13,16 +37,20 @@ type Quaternion = |
|
|
y:float |
|
|
y:float |
|
|
z:float |
|
|
z:float |
|
|
} with |
|
|
} with |
|
|
|
|
|
|
|
|
static member (+) (r: Quaternion, q: Quaternion) = |
|
|
static member (+) (r: Quaternion, q: Quaternion) = |
|
|
{w=r.w+q.w;x=r.x+q.x;y=r.y+q.y;z=r.z+q.z} |
|
|
{w=r.w+q.w;x=r.x+q.x;y=r.y+q.y;z=r.z+q.z} |
|
|
|
|
|
|
|
|
static member (-) (r: Quaternion, q: Quaternion) = |
|
|
static member (-) (r: Quaternion, q: Quaternion) = |
|
|
{w=r.w-q.w;x=r.x-q.x;y=r.y-q.y;z=r.z-q.z} |
|
|
{w=r.w-q.w;x=r.x-q.x;y=r.y-q.y;z=r.z-q.z} |
|
|
|
|
|
|
|
|
static member (*) (r: Quaternion, q: Quaternion) = |
|
|
static member (*) (r: Quaternion, q: Quaternion) = |
|
|
let w = r.w*q.w - r.x*q.x - r.y*q.y - r.z*q.z |
|
|
let w = r.w*q.w - r.x*q.x - r.y*q.y - r.z*q.z |
|
|
let x = r.w*q.x + r.x*q.w - r.y*q.z + r.z*q.y |
|
|
let x = r.w*q.x + r.x*q.w - r.y*q.z + r.z*q.y |
|
|
let y = r.w*q.y + r.x*q.z + r.y*q.w - r.z*q.x |
|
|
let y = r.w*q.y + r.x*q.z + r.y*q.w - r.z*q.x |
|
|
let z = r.w*q.z - r.x*q.y + r.y*q.x + r.z*q.w |
|
|
let z = r.w*q.z - r.x*q.y + r.y*q.x + r.z*q.w |
|
|
{w=w;x=x;y=y;z=z} |
|
|
{w=w;x=x;y=y;z=z} |
|
|
|
|
|
|
|
|
static member (/) (r: Quaternion, q: Quaternion) = |
|
|
static member (/) (r: Quaternion, q: Quaternion) = |
|
|
let d = (r.w**2.0 + r.x**2.0 + r.y**2.0 + r.z**2.0) |
|
|
let d = (r.w**2.0 + r.x**2.0 + r.y**2.0 + r.z**2.0) |
|
|
|
|
|
|
|
|
@ -31,9 +59,20 @@ type Quaternion = |
|
|
let y = (r.w*q.y + r.x*q.z - r.y*q.w - r.z*q.x) / d |
|
|
let y = (r.w*q.y + r.x*q.z - r.y*q.w - r.z*q.x) / d |
|
|
let z = (r.w*q.z - r.x*q.y + r.y*q.x - r.z*q.w) / d |
|
|
let z = (r.w*q.z - r.x*q.y + r.y*q.x - r.z*q.w) / d |
|
|
{w=w;x=x;y=y;z=z} |
|
|
{w=w;x=x;y=y;z=z} |
|
|
|
|
|
|
|
|
static member (/) (q:Quaternion, a) = |
|
|
static member (/) (q:Quaternion, a) = |
|
|
{w=q.w/a; x=q.x/a;y=q.y/a;z=q.z/a} |
|
|
{w=q.w/a; x=q.x/a;y=q.y/a;z=q.z/a} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[<RequireQualifiedAccess; CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] |
|
|
|
|
|
module Quaternion = |
|
|
|
|
|
|
|
|
|
|
|
//Reference: |
|
|
|
|
|
//http://www.astro.rug.nl/software/kapteyn/_downloads/attitude.pdf |
|
|
|
|
|
//http://www.mathworks.com/help/aeroblks/quaternionmultiplication.html |
|
|
|
|
|
//http://www.mathworks.com/help/aeroblks/quaterniondivision.html |
|
|
|
|
|
//https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#The_conjugation_operation |
|
|
|
|
|
|
|
|
let norm q = |
|
|
let norm q = |
|
|
q.w**2.0 + q.x**2.0 + q.y**2.0 + q.z**2.0 |
|
|
q.w**2.0 + q.x**2.0 + q.y**2.0 + q.z**2.0 |
|
|
|
|
|
|
|
|
|