cvs: pear /Math_Quaternion Quaternion.php QuaternionOp.php package.xml testquaternion.php /Math_Quaternion/test testMath_Quaternion.php test_cwt.exp
test_cwt.php

From: Date: Thu, 02 Jan 2003 09:48:19 +0000
Subject: cvs: pear /Math_Quaternion Quaternion.php QuaternionOp.php package.xml testquaternion.php /Math_Quaternion/test testMath_Quaternion.php test_cwt.exp
test_cwt.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-8042@lists.php.net to get a copy of this message
jmcastagnetto Thu Jan 2 04:48:19 2003 EDT Added files: /pear/Math_Quaternion/test testMath_Quaternion.php test_cwt.exp test_cwt.php Removed files: /pear/Math_Quaternion testquaternion.php Modified files: /pear/Math_Quaternion Quaternion.php QuaternionOp.php package.xml Log: Preparing for release.

Index: pear/Math_Quaternion/Quaternion.php diff -u pear/Math_Quaternion/Quaternion.php:1.1 pear/Math_Quaternion/Quaternion.php:1.2 --- pear/Math_Quaternion/Quaternion.php:1.1 Wed Nov 27 17:32:15 2002 +++ pear/Math_Quaternion/Quaternion.php Thu Jan 2 04:48:19 2003 @@ -16,7 +16,7 @@ // | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // -// $Id: Quaternion.php,v 1.1 2002/11/27 22:32:15 jmcastagnetto Exp $ +// $Id: Quaternion.php,v 1.2 2003/01/02 09:48:19 jmcastagnetto Exp $ // include_once "PEAR.php"; @@ -44,8 +44,43 @@ * * Originally this class was part of NumPHP (Numeric PHP package) * + * Example: + * <pre> + * 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()); + * </pre> + * + * Output from example: + * <pre> + * 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 + * ) + * </pre> + * * @author Jesus M. Castagnetto <jmcastagnetto@php.net> - * @version 0.9 + * @version 0.7 * @access public * @package Math_Quaternion */ @@ -106,9 +141,14 @@ * @return string * @access public */ - function toString () {/*{{{*/ - return ( $this->getReal()." + ".$this->getI()."i + ". - $this->getJ()."j + ".$this->getK()."k"); + function toString ($fmt = 'number') {/*{{{*/ + if ($fmt == 'vector') { + return '[ '.$this->getReal().' '.$this->getI() + .' '.$this->getJ().' '.$this->getK().' ]'; + } else { + return ( $this->getReal()." + ".$this->getI()."i + ". + $this->getJ()."j + ".$this->getK()."k"); + } }/*}}}*/ /** Index: pear/Math_Quaternion/QuaternionOp.php diff -u pear/Math_Quaternion/QuaternionOp.php:1.1 pear/Math_Quaternion/QuaternionOp.php:1.2 --- pear/Math_Quaternion/QuaternionOp.php:1.1 Wed Nov 27 17:32:15 2002 +++ pear/Math_Quaternion/QuaternionOp.php Thu Jan 2 04:48:19 2003 @@ -16,7 +16,7 @@ // | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> | // +----------------------------------------------------------------------+ // -// $Id: QuaternionOp.php,v 1.1 2002/11/27 22:32:15 jmcastagnetto Exp $ +// $Id: QuaternionOp.php,v 1.2 2003/01/02 09:48:19 jmcastagnetto Exp $ // include_once 'PEAR.php'; @@ -27,15 +27,87 @@ * * Originally this class was part of NumPHP (Numeric PHP package) * + * Example: + * <pre> + * require_once 'Math/QuaternionOp.php'; + * + * $a = new Math_Quaternion(2,4,2,-0.5); + * $b = new Math_Quaternion(1,2,3,0.5); + * + * if (!Math_QuaternionOp::areEqual($a, Math_QuaternionOp::negative($a))) { + * echo "a and neg(a) are different\n"; + * } + * $t=Math_QuaternionOp::negative($a); + * echo "Neg(a) is ".$t->toString()."\n"; + * $t=Math_QuaternionOp::conjugate($a); + * echo "Conj(a) is ".$t->toString()."\n"; + * $t=Math_QuaternionOp::inverse($a); + * echo "Inv(a) is ".$t->toString()."\n"; + * $t=Math_QuaternionOp::multReal($a, 1.23); + * echo "MultReal(a, 1.23) is ".$t->toString()."\n"; + * + * echo "====\n"; + * $t=Math_QuaternionOp::mult($a,$b); + * echo "a*b: ".$t->toString()."\n"; + * $t=Math_QuaternionOp::mult($b,$a); + * echo "b*a: ".$t->toString()."\n"; + * $t=Math_QuaternionOp::mult($a,Math_QuaternionOp::conjugate($a)); + * echo "a*a': ".$t->toString()."\n"; + * echo "length(a*a'): ".$t->length()."\n"; + * $t=Math_QuaternionOp::add($a,$b); + * echo "a+b: ".$t->toString()."\n"; + * $t=Math_QuaternionOp::sub($a,$b); + * echo "a-b: ".$t->toString()."\n"; + * $t=Math_QuaternionOp::sub($b,$a); + * echo "b-a: ".$t->toString()."\n"; + * $t=Math_QuaternionOp::sub($b,Math_QuaternionOp::conjugate($a)); + * echo "b-a': ".$t->toString()."\n"; + * $t=Math_QuaternionOp::sub(Math_QuaternionOp::conjugate($b), $a); + * echo "b'-a: ".$t->toString()."\n"; + * $t=Math_QuaternionOp::sub(Math_QuaternionOp::conjugate($b), Math_QuaternionOp::conjugate($a)); + * echo "b'-a': ".$t->toString()."\n"; + * $t = Math_QuaternionOp::div($a, $b); + * echo "a/b: ".$t->toString()."\n"; + * $t = Math_QuaternionOp::div($b, $a); + * echo "b/a: ".$t->toString()."\n"; + * </pre> + * + * Output from example: + * <pre> + * a and neg(a) are different + * Neg(a) is -2 + -4i + -2j + 0.5k + * Conj(a) is 2 + -4i + -2j + 0.5k + * Inv(a) is 0.40613846605345 + -0.8122769321069i + -0.40613846605345j + 0.10153461651336k + * MultReal(a, 1.23) is 2.46 + 4.92i + 2.46j + -0.615k + * ==== + * a*b: -11.25 + 6i + 9j + 1.5k + * b*a: -18.25 + 12i + 6j + -1.5k + * a*a': -16.25 + -16i + -8j + 2k + * length(a*a'): 24.25 + * a+b: 3 + 6i + 5j + 0k + * a-b: 1 + 2i + -1j + -1k + * b-a: -1 + -2i + 1j + 1k + * b-a': -1 + 6i + 5j + 0k + * b'-a: -1 + -6i + -5j + 0k + * b'-a': -1 + 2i + -1j + -1k + * a/b: -19.720187057174 + 9.059625885652i + 4.529812942826j + -1.1324532357065k + * b/a: -12.843861533947 + 2.8122769321069i + 4.2184153981603j + 0.70306923302672k + * </pre> + * * @author Jesus M. Castagnetto <jmcastagnetto@php.net> - * @version 0.9 + * @version 0.7 * @access public * @package Math_Quaternion */ - class Math_QuaternionOp {/*{{{*/ - /* is q1 a quaternion? */ + /** + * Whether the object is a Math_Quaternion instance + * + * @param object Math_Quaternion $q1 + * @return boolean TRUE if object is a Math_Quaternion, FALSE otherwise + * @access public + */ function isQuaternion (&$q1) {/*{{{*/ if (function_exists('is_a')) { return is_a($q1, 'math_quaternion'); @@ -45,30 +117,49 @@ } }/*}}}*/ - /* Q = conj(q1) */ + /** + * Calculate the conjugate of a quaternion + * + * @param object Math_Quaternion $q1 + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + */ function &conjugate (&$q1) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1)) { - return PEAR::raiseError("Parameter needs to be a quaternion object"); + return PEAR::raiseError("Parameter needs to be a Math_Quaternion object"); } $q2 = $q1->clone(); $q2->conjugate(); return $q2; }/*}}}*/ - /* Q = -q1 */ - function &negative (&$q1) {/*{{{*/ + /** + * Negates the given quaternion + * + * @param object Math_Quaternion $q1 + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + */ + function &negate (&$q1) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1)) { - return PEAR::raiseError("Parameter needs to be a quaternion object"); + return PEAR::raiseError("Parameter needs to be a Math_Quaternion object"); } $q2 = $q1->clone(); $q2->negate(); return $q2; }/*}}}*/ - /* Q = 1/q1 */ + /** + * Inverts the given quaternion + * + * @param object Math_Quaternion $q1 + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + * @see Math_QuaternionOp::multReal + */ function &inverse (&$q1) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1)) { - return PEAR::raiseError("Parameter needs to be a quaternion object"); + return PEAR::raiseError("Parameter needs to be a Math_Quaternion object"); } $c = Math_QuaternionOp::conjugate($q1); $norm = $q1->norm(); @@ -79,35 +170,68 @@ return Math_QuaternionOp::multReal($c, $invmult); }/*}}}*/ + /** + * Checks if two quaternions represent the same number + * + * @param object Math_Quaternion $q1 + * @param object Math_Quaternion $q2 + * @return mixed PEAR_Error on error, TRUE if q1 == q2, FALSE otherwise + * @access public + */ function areEqual (&$q1, &$q2) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1) || !Math_QuaternionOp::isQuaternion($q2)) { - return PEAR::raiseError("Parameters need to be quaternion objects"); + return PEAR::raiseError("Parameters need to be Math_Quaternion objects"); } return ( $q1->getReal() == $q2->getReal() && $q1->getI() == $q2->getI() && $q1->getJ() == $q2->getJ() && $q1->getK() == $q2->getK() ); }/*}}}*/ + /** + * Adds two quaternions: q1 + q2 + * + * @param object Math_Quaternion $q1 + * @param object Math_Quaternion $q2 + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + */ function &add (&$q1, &$q2) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1) || !Math_QuaternionOp::isQuaternion($q2)) { - return PEAR::raiseError("Parameters need to be quaternion objects"); + return PEAR::raiseError("Parameters need to be Math_Quaternion objects"); } return new Math_Quaternion( $q1->getReal() + $q2->getReal(), $q1->getI() + $q2->getI(), $q1->getJ() + $q2->getJ(), $q1->getK() + $q2->getK() ); }/*}}}*/ + /** + * Substracts two quaternions: q1 - q2 + * + * @param object Math_Quaternion $q1 + * @param object Math_Quaternion $q2 + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + */ function &sub (&$q1, &$q2) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1) || !Math_QuaternionOp::isQuaternion($q2)) { - return PEAR::raiseError("Parameters need to be quaternion objects"); + return PEAR::raiseError("Parameters need to be Math_Quaternion objects"); } - return Math_QuaternionOp::add($q1, Math_QuaternionOp::negative($q2)); + return Math_QuaternionOp::add($q1, Math_QuaternionOp::negate($q2)); }/*}}}*/ + /** + * Multiplies two quaternions: q1 * q2 + * It uses a fast multiplication algorithm. + * + * @param object Math_Quaternion $q1 + * @param object Math_Quaternion $q2 + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + */ function &mult (&$q1, &$q2) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1) || !Math_QuaternionOp::isQuaternion($q2)) { - return PEAR::raiseError("Parameters need to be quaternion objects"); + return PEAR::raiseError("Parameters need to be Math_Quaternion objects"); } // uses the fast multiplication algorithm - $a = $q1->getReal(); $q1im = $q2->getAllIm(); + $a = $q1->getReal(); $q1im = $q1->getAllIm(); $b = $q1im["i"]; $c = $q1im["j"]; $d = $q1im["k"]; $x = $q2->getReal(); $q2im = $q2->getAllIm(); @@ -132,9 +256,17 @@ return new Math_Quaternion($r, $i , $j, $k); }/*}}}*/ + /** + * Divides two quaternions: q1 / q2 + * + * @param object Math_Quaternion $q1 + * @param object Math_Quaternion $q2 + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + */ function &div (&$q1, &$q2) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1) || !Math_QuaternionOp::isQuaternion($q2)) { - return PEAR::raiseError("Parameters need to be quaternion objects"); + return PEAR::raiseError("Parameters need to be Math_Quaternion objects"); } $i2 = Math_QuaternionOp::inverse($q2); if (PEAR::isError($i2)) { @@ -143,9 +275,17 @@ return Math_QuaternionOp::mult($i2, $q1); }/*}}}*/ + /** + * Multiplies a quaternion by a real number: q1 * realnum + * + * @param object Math_Quaternion $q1 + * @param float $realnum + * @return object a Math_Quaternion on success, PEAR_Error otherwise + * @access public + */ function &multReal (&$q1, $realnum) {/*{{{*/ if (!Math_QuaternionOp::isQuaternion($q1) || !is_numeric($realnum)) { - return PEAR::raiseError("A quaternion object and a real number are needed"); + return PEAR::raiseError("A Math_Quaternion object and a real number are needed"); } return new Math_Quaternion ( $realnum * $q1->getReal(), $realnum * $q1->getI(), $realnum * $q1->getJ(), $realnum * $q1->getK() ); Index: pear/Math_Quaternion/package.xml diff -u pear/Math_Quaternion/package.xml:1.1 pear/Math_Quaternion/package.xml:1.2 --- pear/Math_Quaternion/package.xml:1.1 Wed Nov 27 17:32:15 2002 +++ pear/Math_Quaternion/package.xml Thu Jan 2 04:48:19 2003 @@ -22,16 +22,21 @@ <release> <license>PHP</license> - <version>0.8</version> + <version>0.7</version> <date>2002-11-27</date> <notes> - Initial release under PEAR. + Quaternion manipulation package. Initial release under PEAR. </notes> <state>beta</state> <filelist> <dir name="/" baseinstalldir="Math"> <file role="php">Quaternion.php</file> <file role="php">QuaternionOp.php</file> + <dir name="test" role="test"> + <file role="php">testMath_Quaternion.php</file> + <file role="php">test_cwt.php</file> + <file role="php">test_cwt.exp</file> + </dir> </dir> </filelist> <deps> Index: pear/Math_Quaternion/test/testMath_Quaternion.php +++ pear/Math_Quaternion/test/testMath_Quaternion.php <?php /** * To test Math_Quaternion * $Id: testMath_Quaternion.php,v 1.1 2003/01/02 09:48:19 jmcastagnetto Exp $ */ require_once 'Math/QuaternionOp.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()); if (!Math_QuaternionOp::areEqual($a, Math_QuaternionOp::negative($a))) {echo "a and neg(a) are different\n";} $t=Math_QuaternionOp::negative($a); echo "Neg(a) is ".$t->toString()."\n"; $t=Math_QuaternionOp::conjugate($a); echo "Conj(a) is ".$t->toString()."\n"; $t=Math_QuaternionOp::inverse($a); echo "Inv(a) is ".$t->toString()."\n"; $t=Math_QuaternionOp::multReal($a, 1.23); echo "MultReal(a, 1.23) is ".$t->toString()."\n"; echo "====\n"; $t=Math_QuaternionOp::mult($a,$b); echo "a*b: ".$t->toString()."\n"; $t=Math_QuaternionOp::mult($b,$a); echo "b*a: ".$t->toString()."\n"; $t=Math_QuaternionOp::mult($a,Math_QuaternionOp::conjugate($a)); echo "a*a': ".$t->toString()."\n"; echo "length(a*a'): ".$t->length()."\n"; $t=Math_QuaternionOp::add($a,$b); echo "a+b: ".$t->toString()."\n"; $t=Math_QuaternionOp::sub($a,$b); echo "a-b: ".$t->toString()."\n"; $t=Math_QuaternionOp::sub($b,$a); echo "b-a: ".$t->toString()."\n"; $t=Math_QuaternionOp::sub($b,Math_QuaternionOp::conjugate($a)); echo "b-a': ".$t->toString()."\n"; $t=Math_QuaternionOp::sub(Math_QuaternionOp::conjugate($b), $a); echo "b'-a: ".$t->toString()."\n"; $t=Math_QuaternionOp::sub(Math_QuaternionOp::conjugate($b), Math_QuaternionOp::conjugate($a)); echo "b'-a': ".$t->toString()."\n"; $t = Math_QuaternionOp::div($a, $b); echo "a/b: ".$t->toString()."\n"; $t = Math_QuaternionOp::div($b, $a); echo "b/a: ".$t->toString()."\n"; ?> Index: pear/Math_Quaternion/test/test_cwt.exp +++ pear/Math_Quaternion/test/test_cwt.exp * Expected output from tests at * http://www.cs.umd.edu/Outreach/hsContest99/questions/node6.html * $Id: test_cwt.exp,v 1.1 2003/01/02 09:48:19 jmcastagnetto Exp $ :::::::::::::: out1.ok :::::::::::::: [0] = [ 1 1 0 0 ] [1] = [ 1 0 1 0 ] [2] = [ 2 1 1 0 ] [9] = [ 1 1 1 1 ] [9] = [ -1 0 -1 0 ] :::::::::::::: out2.ok :::::::::::::: [0] = [ 1 0.5 0 0 ] [1] = [ 1 -1 0 0 ] [2] = [ 0 0 1 0 ] [3] = [ 0 0 0 1 ] [3] = [ 0 0 0 -1 ] [6] = [ 0 0 1 -1 ] [4] = [ 1.5 -0.5 0 0 ] [4] = [ 1.75 0.25 0 0 ] :::::::::::::: out3.ok :::::::::::::: [1] = [ 1 2 3 1 ] [2] = [ 2 1 0 1 ] [5] = [ 1 2 0 3 ] [4] = [ -1 8 5 0 ] [3] = [ -6 13 -1 -2 ] [8] = [ -5 15 2 -1 ] [8] = [ 5 -15 -2 1 ] [8] = [ -5 15 2 -1 ] :::::::::::::: out4.ok :::::::::::::: [0] = [ 1 1 1 1 ] [1] = [ 4 3 2 1 ] [2] = [ -1 -1 -1 -1 ] [3] = [ 2 -8 -4 -6 ] [4] = [ -20 8 4 0 ] [5] = [ 40 200 40 120 ] [6] = [ 20 208 44 120 ] [7] = [ -20 -208 -44 -120 ] [8] = [ 20 -8 -4 0 ] [9] = [ 0 -216 -48 -120 ] :::::::::::::: out5.ok :::::::::::::: [0] = [ 1 2 1 -1 ] [1] = [ 0 0 0 0 ] [2] = [ 1 2 1 -1 ] [1] = [ -5 4 2 -2 ] [2] = [ -1 -2 -1 1 ] [1] = [ 5 -4 -2 2 ] [3] = [ -1 1 0 0 ] [4] = [ 1 -1 0 0 ] [5] = [ 0 2 0 0 ] [5] = [ 0 -2 0 0 ] [5] = [ -4 0 0 0 ] [5] = [ 16 0 0 0 ] [5] = [ 256 0 0 0 ] :::::::::::::: out6.ok :::::::::::::: [8] = [ 1.22 -1.84 -0.32 -3.21 ] [7] = [ -0.82 -0.51 1.51 1.13 ] [3] = [ 1.28 -3.52 -3.14 -4.84 ] [2] = [ -0.74 -0.25 -4.39 -8.22 ] [5] = [ -2.28 -1.19 2.84 -2.34 ] [1] = [ 1.1 -0.58 -9.53 7.27 ] [6] = [ -4.63 -3.54 8.94 -2.28 ] [9] = [ -0.13 -0.32 -1.04 8.49 ] [4] = [ -8.39 -9.27 8.01 4.03 ] [0] = [ -7.43 -0.14 -5.24 -7.01 ] [0] = [ -7.2287 -100.745 70.1275 -63.4321 ] [1] = [ 16.9637 110.406 -4.3619 -14.2581 ] [8] = [ 26.1727 5.904 -17.876 8.9639 ] [6] = [ -8.9318 -8.2809 -19.4851 -2.5763 ] Index: pear/Math_Quaternion/test/test_cwt.php +++ pear/Math_Quaternion/test/test_cwt.php <?php // $Id: test_cwt.php,v 1.1 2003/01/02 09:48:19 jmcastagnetto Exp $ // Using the data by Chau-Wen Tseng // http://www.cs.umd.edu/Outreach/hsContest99/questions/node6.html include_once 'Math/QuaternionOp.php'; $fmt = 'vector'; // // Test 1 // $q0 = new Math_Quaternion(1,1,0,0); $q1 = new Math_Quaternion(1,0,1,0); echo "* Test 1:\n"; echo 'q0 = '.$q0->toString($fmt)."\n"; echo 'q1 = '.$q1->toString($fmt)."\n"; $q2 = Math_QuaternionOp::add($q0, $q1); echo 'q2 = q0 + q1 = '.$q2->toString($fmt)."\n"; $q9 = Math_QuaternionOp::mult($q0, $q1); echo 'q9 = q0 * q1 = '.$q9->toString($fmt)."\n"; $q9 = Math_QuaternionOp::negate($q1); echo 'q9 = -q1 = '.$q9->toString($fmt)."\n"; // // Test 2 // $q0 = new Math_Quaternion(1,0.5,0,0); $q1 = new Math_Quaternion(1,-1,0,0); $q2 = new Math_Quaternion(0,0,1,0); $q3 = new Math_Quaternion(0,0,0,1); echo "\n* Test 2:\n"; echo 'q0 = '.$q0->toString($fmt)."\n"; echo 'q1 = '.$q1->toString($fmt)."\n"; echo 'q2 = '.$q2->toString($fmt)."\n"; echo 'q3 = '.$q3->toString($fmt)."\n"; $q3->negate(); echo 'q3 = -q3 = '.$q3->toString($fmt)."\n"; $q6 = Math_QuaternionOp::add($q2, $q3); echo 'q6 = q2 + q3 = '.$q6->toString($fmt)."\n"; $q4 = Math_QuaternionOp::mult($q0, $q1); echo 'q4 = q0 * q1 = '.$q4->toString($fmt)."\n"; $q4 = Math_QuaternionOp::mult($q4, $q0); echo 'q4 = q4 * q0 = '.$q4->toString($fmt)."\n"; // // Test 3 // $q1 = new Math_Quaternion(1,2,3,1); $q2 = new Math_Quaternion(2,1,0,1); $q5 = new Math_Quaternion(1,2,0,3); echo "\n* Test 3:\n"; echo 'q1 = '.$q1->toString($fmt)."\n"; echo 'q2 = '.$q2->toString($fmt)."\n"; echo 'q5 = '.$q5->toString($fmt)."\n"; $q4 = Math_QuaternionOp::mult($q1, $q2); echo 'q4 = q1 * q2 = '.$q4->toString($fmt)."\n"; $q3 = Math_QuaternionOp::mult($q1, $q5); echo 'q3 = q1 * q5 = '.$q3->toString($fmt)."\n"; $q8 = Math_QuaternionOp::add($q1, $q3); echo 'q8 = q1 + q3 = '.$q8->toString($fmt)."\n"; $q8->negate(); echo 'q8 = -q8 = '.$q8->toString($fmt)."\n"; $q8->negate(); echo 'q8 = -q8 = '.$q8->toString($fmt)."\n"; // // Test 4 // $q0 = new Math_Quaternion(1,1,1,1); $q1 = new Math_Quaternion(4,3,2,1); echo "\n* Test 4:\n"; echo 'q0 = '.$q0->toString($fmt)."\n"; echo 'q1 = '.$q1->toString($fmt)."\n"; $q2 = Math_QuaternionOp::negate($q0); echo 'q2 = -q0 = '.$q2->toString($fmt)."\n"; $q3 = Math_QuaternionOp::mult($q1, $q2); echo 'q3 = q1 * q2 = '.$q3->toString($fmt)."\n"; $q4 = Math_QuaternionOp::mult($q2, $q3); echo 'q4 = q2 * q3 = '.$q4->toString($fmt)."\n"; $q5 = Math_QuaternionOp::mult($q3, $q4); echo 'q5 = q3 * q4 = '.$q5->toString($fmt)."\n"; $q6 = Math_QuaternionOp::add($q4, $q5); echo 'q6 = q4 + q5 = '.$q6->toString($fmt)."\n"; $q7 = Math_QuaternionOp::negate($q6); echo 'q7 = -q6 = '.$q7->toString($fmt)."\n"; $q8 = Math_QuaternionOp::add($q5, $q7); echo 'q8 = q5 + q7 = '.$q8->toString($fmt)."\n"; $q9 = Math_QuaternionOp::add($q7, $q8); echo 'q9 = q7 + q8 = '.$q9->toString($fmt)."\n"; // // Test 5 // $q0 = new Math_Quaternion(1,2,1,-1); $q1 = new Math_Quaternion(0,0,0,0); echo "\n* Test 5:\n"; echo 'q0 = '.$q0->toString($fmt)."\n"; echo 'q1 = '.$q1->toString($fmt)."\n"; $q2 = Math_QuaternionOp::add($q0, $q1); echo 'q2 = q0 + q1 = '.$q2->toString($fmt)."\n"; $q1 = Math_QuaternionOp::mult($q2, $q0); echo 'q1 = q2 * q0 = '.$q1->toString($fmt)."\n"; $q2 = Math_QuaternionOp::negate($q0); echo 'q2 = negate(a) = '.$q2->toString($fmt)."\n"; $q1 = Math_QuaternionOp::mult($q2, $q0); echo 'q1 = q2 * q0 = '.$q1->toString($fmt)."\n"; $q3 = new Math_Quaternion(-1,1,0,0); $q4 = new Math_Quaternion(1,-1,0,0); echo 'q3 = '.$q3->toString($fmt)."\n"; echo 'q4 = '.$q4->toString($fmt)."\n"; $q5 = Math_QuaternionOp::mult($q3, $q4); echo 'q5 = q3 * q4 = '.$q5->toString($fmt)."\n"; $q5->negate(); echo 'q5 = -q5 = '.$q5->toString($fmt)."\n"; $q5 = Math_QuaternionOp::mult($q5, $q5); echo 'q5 = q5 * q5 = '.$q5->toString($fmt)."\n"; $q5 = Math_QuaternionOp::mult($q5, $q5); echo 'q5 = q5 * q5 = '.$q5->toString($fmt)."\n"; $q5 = Math_QuaternionOp::mult($q5, $q5); echo 'q5 = q5 * q5 = '.$q5->toString($fmt)."\n"; // // Test 6 // echo "\n* Test 6:\n"; $q8 = new Math_Quaternion(1.22,-1.84,-0.32,-3.21); $q7 = new Math_Quaternion(-0.82,-0.51,1.51,1.13); $q3 = new Math_Quaternion(1.28,-3.52,-3.14,-4.84); $q2 = new Math_Quaternion(-0.74,-0.25,-4.39,-8.22); $q5 = new Math_Quaternion(-2.28,-1.19,2.84,-2.34); $q1 = new Math_Quaternion(1.10,-0.58,-9.53,7.27); $q6 = new Math_Quaternion(-4.63,-3.54,8.94,-2.28); $q9 = new Math_Quaternion(-0.13,-0.32,-1.04,8.49); $q4 = new Math_Quaternion(-8.39,-9.27,8.01,4.03); $q0 = new Math_Quaternion(-7.43,-0.14,-5.24,-7.01); echo 'q8 = '.$q8->toString($fmt)."\n"; echo 'q7 = '.$q7->toString($fmt)."\n"; echo 'q3 = '.$q3->toString($fmt)."\n"; echo 'q2 = '.$q2->toString($fmt)."\n"; echo 'q5 = '.$q5->toString($fmt)."\n"; echo 'q1 = '.$q1->toString($fmt)."\n"; echo 'q6 = '.$q6->toString($fmt)."\n"; echo 'q9 = '.$q9->toString($fmt)."\n"; echo 'q4 = '.$q4->toString($fmt)."\n"; echo 'q0 = '.$q0->toString($fmt)."\n"; $q0 = Math_QuaternionOp::mult($q0, $q1); echo 'q0 = q0 * q1 = '.$q0->toString($fmt)."\n"; $q1 = Math_QuaternionOp::mult($q1, $q2); echo 'q1 = q1 * q2 = '.$q1->toString($fmt)."\n"; $q8 = Math_QuaternionOp::mult($q9, $q8); echo 'q8 = q9 * q8 = '.$q8->toString($fmt)."\n"; $q6 = Math_QuaternionOp::mult($q7, $q6); echo 'q6 = q7 * q6 = '.$q6->toString($fmt)."\n"; ?>
« previous php.pear.cvs (#8042) next »