-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start basics of a quaternion library.
- Loading branch information
1 parent
7d2a313
commit 6b4669d
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
with Ada.Numerics.Generic_Elementary_Functions; | ||
package body BBS.Numerical.quaternion is | ||
package elem is new Ada.Numerics.Generic_Elementary_Functions(f); | ||
-- | ||
-- Basic operations | ||
-- | ||
function "+" (Left, Right : quaternion) return quaternion is | ||
begin | ||
return (r => Left.r + Right.r, | ||
i => Left.i + Right.i, | ||
j => Left.j + Right.j, | ||
k => Left.k + Right.k); | ||
end; | ||
-- | ||
function "-" (Left, Right : quaternion) return quaternion is | ||
begin | ||
return (r => Left.r - Right.r, | ||
i => Left.i - Right.i, | ||
j => Left.j - Right.j, | ||
k => Left.k - Right.k); | ||
end; | ||
|
||
function "*" (Left : f; Right : quaternion) return quaternion is | ||
begin | ||
return (r => Left * Right.r, | ||
i => Left * Right.i, | ||
j => Left * Right.j, | ||
k => Left * Right.k); | ||
end; | ||
-- | ||
function "*" (Left : quaternion; Right : f) return quaternion is | ||
begin | ||
return (r => Left.r * Right, | ||
i => Left.i * Right, | ||
j => Left.j * Right, | ||
k => Left.k * Right); | ||
end; | ||
-- | ||
function "/" (Left : quaternion; Right : f) return quaternion is | ||
begin | ||
return (r => Left.r / Right, | ||
i => Left.i / Right, | ||
j => Left.j / Right, | ||
k => Left.k / Right); | ||
end; | ||
-- | ||
function magnitude(self : in quaternion) return f'Base is | ||
begin | ||
return elem.Sqrt(self.r * self.r + self.i * self.i + | ||
self.j * self.j + self.k * self.k); | ||
end; | ||
-- | ||
end BBS.Numerical.quaternion; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- | ||
-- This is a simple package that supports basic functions on quaternions. | ||
-- | ||
generic | ||
type F is digits <>; | ||
package BBS.Numerical.quaternion is | ||
type quaternion is tagged record | ||
r : f'Base; -- Scalar part | ||
i : f'Base; -- i, j, and k are the vector part | ||
j : f'Base; | ||
k : f'Base; | ||
end record; | ||
-- | ||
-- Basic arithmatic operations | ||
-- | ||
function "+" (Left, Right : quaternion) return quaternion; | ||
function "-" (Left, Right : quaternion) return quaternion; | ||
|
||
function "*" (Left : f; Right : quaternion) return quaternion; | ||
function "*" (Left : quaternion; Right : f) return quaternion; | ||
|
||
function "/" (Left : quaternion; Right : f) return quaternion; | ||
|
||
function magnitude(self : in quaternion) return f'Base; | ||
|
||
end BBS.Numerical.quaternion; |