New package proposal: Math_Quaternion

From: Date: Wed, 27 Nov 2002 02:36:46 +0000
Subject: New package proposal: Math_Quaternion
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-11142@lists.php.net to get a copy of this message
Got some more code (partly PEARIzed, lacks comments for now) to deal with Quaternions and their operations. For now I have the basic operations there, eventually there will be some nice vector rotation and similar operations too. Get the code doing: pear install http://www.scripps.edu/~jesusmc/stuff/Math_Quaternion-0.8.tgz Any comments on the naming/design/algorithms of the package will be greatly appreciated. And if you want to test the package, use the code below: <?php /* * To test class.quaternion.php * numPHP (c) Jesus M. Castagnetto 1999,2000. * $Id: testquaternion.php,v 1.4 2000/08/19 11:38:06 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"; ?> ===== --- Jesus M. Castagnetto (jcastagnetto@yahoo.com) Research: http://metallo.scripps.edu/ Personal: http://www.castagnetto.org/ __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com

« previous php.pear.dev (#11142) next »