Math_Quaternion
[ class tree: Math_Quaternion ] [ index: Math_Quaternion ] [ all elements ]

Class: Math_Quaternion

Source Location: /Math_Quaternion-0.8.0/Math/Quaternion.php

Class Overview


Math_Quaternion: class to represent an manipulate quaternions (q = a + b*i + c*j + d*k)


Author(s):

Version:

  • 0.7

Methods


Inherited Variables

Inherited Methods


Class Details

[line 87]
Math_Quaternion: class to represent an manipulate quaternions (q = a + b*i + c*j + d*k)

A quaternion is an extension of the idea of complex numbers In 1844 Hamilton described a system in which numbers were composed of a real part and 3 imaginary and independent parts (i,j,k), such that:

i^2 = j^2 = k^2 = -1 and ij = k, jk = i, ki = j and ji = -k, kj = -i, ik = -j

The above are known as "Hamilton's rules"

Interesting references on quaternions:

  • Sir William Rowan Hamilton "On Quaternions", Proceedings of the Royal Irish Academy, Nov. 11, 1844, vol. 3 (1847), 1-16 (http://www.maths.tcd.ie/pub/HistMath/People/Hamilton/Quatern2/Quatern2.html)
  • Quaternion (from MathWorld): http://mathworld.wolfram.com/Quaternion.html
Originally this class was part of NumPHP (Numeric PHP package)

Example:

 require_once 'Math/Quaternion.php';

 $a = new Math_Quaternion(2,4,2,-0.5);
 $b = new Math_Quaternion(1,2,3,0.5);

 echo "a: ".$a->toString()."\n";
 echo "b: ".$b->toString()."\n";
 $t = Math_QuaternionOp::conjugate($a);
 echo "a': ".$t->toString()."\n";
 $t = Math_QuaternionOp::conjugate($b);
 echo "b': ".$t->toString()."\n";
 echo "length(a): ".$a->length()."  length2(a): ".$a->length2()."\n";
 echo "real(a): ".$a->getReal()."\nimag(a): ";

 print_r($a->getAllIm());

Output from example:

 a: 2 + 4i + 2j + -0.5k
 b: 1 + 2i + 3j + 0.5k
 a': 2 + -4i + -2j + 0.5k
 b': 1 + -2i + -3j + -0.5k
 length(a): 4.9244289008981  length2(a): 24.25
 real(a): 2
 imag(a): Array
 (
     [i] => 4
     [j] => 2
     [k] => -0.5
 )



[ Top ]


Method Detail

Math_Quaternion (Constructor)   [line 131]

object Math_Quaternion Math_Quaternion( float $real, float $i, float $j, float $k)

Constructor for Math_Quaternion
  • Access: public

Parameters:

float   $real   — 
float   $i   — 
float   $j   — 
float   $k   — 

[ Top ]

conjugate   [line 217]

void conjugate( )

Conjugates the quaternion
  • Access: public

[ Top ]

getAllIm   [line 348]

array getAllIm( )

Returns an associative array of I, J, K
  • Access: public

[ Top ]

getI   [line 285]

float getI( )

Returns I
  • Access: public

[ Top ]

getJ   [line 306]

float getJ( )

Returns J
  • Access: public

[ Top ]

getK   [line 327]

float getK( )

Returns K
  • Access: public

[ Top ]

getReal   [line 264]

float getReal( )

Returns the real part
  • Access: public

[ Top ]

length   [line 184]

float length( )

Returns the length (norm). Alias of Math_Quaternion:norm()
  • Access: public

[ Top ]

length2   [line 160]

float length2( )

Returns the square of the norm (length)
  • Access: public

[ Top ]

makeClone   [line 242]

object Math_Quaternion &makeClone( )

Clones the quaternion
  • Access: public

[ Top ]

negate   [line 229]

void negate( )

Negates the quaternion
  • Access: public

[ Top ]

norm   [line 174]

float norm( )

Returns the norm of the quaternion
  • Access: public

[ Top ]

normalize   [line 194]

mixed normalize( )

Normalizes the quaternion
  • Return: True on success, PEAR_Error object otherwise
  • Access: public

[ Top ]

setAllIm   [line 336]

void setAllIm( $i, $j, $k)

Sets I, J, K
  • Access: public

Parameters:

   $i   — 
   $j   — 
   $k   — 

[ Top ]

setI   [line 275]

void setI( float $i)

Sets I
  • Access: public

Parameters:

float   $i   — 

[ Top ]

setJ   [line 296]

void setJ( float $j)

Sets J
  • Access: public

Parameters:

float   $j   — 

[ Top ]

setK   [line 317]

void setK( float $k)

Sets K
  • Access: public

Parameters:

float   $k   — 

[ Top ]

setReal   [line 254]

void setReal( float $real)

Sets the real part
  • Access: public

Parameters:

float   $real   — 

[ Top ]

toString   [line 144]

string toString( [ $fmt = 'number'])

Simple string representation of the quaternion
  • Access: public

Parameters:

   $fmt   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:39:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.