cvs: pear /Math_Vector/examples tuple_creation.php vector_creation.php vector_operations.php

From: Date: Wed, 24 Apr 2002 23:26:02 +0000
Subject: cvs: pear /Math_Vector/examples tuple_creation.php vector_creation.php vector_operations.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-3526@lists.php.net to get a copy of this message
jmcastagnetto Wed Apr 24 19:26:02 2002 EDT Added files: /pear/Math_Vector/examples tuple_creation.php vector_creation.php vector_operations.php Log: Examples of use Index: pear/Math_Vector/examples/tuple_creation.php +++ pear/Math_Vector/examples/tuple_creation.php <?php require_once "Math/Vector/Tuple.php"; echo "Creating tuple\n"; $t = new Math_Tuple(array(2,3,4)); $t->toString()."\n"; echo "Tuple size: ".$t->getSize()."\n"; echo "Adding element value 7\n"; $t->addElement(7); echo "Tuple size: ".$t->getSize()."\n"; echo "Tuple toString: ".$t->toString()."\n"; echo "Setting element 1 to 11\n"; $t->setElement(1, 11); echo "Tuple toString: ".$t->toString()."\n"; echo "Maximum element value: ".$t->getMax()."\n"; echo "Minimum element value: ".$t->getMin()."\n"; echo "Index of maximum value: ".$t->getMaxIndex()."\n"; echo "Index of minimum value: ".$t->getMinIndex()."\n"; echo "Remove element 2\n"; $t->delElement(2); echo "Tuple toString: ".$t->toString()."\n"; echo "Get element 2: ".$t->getElement(2)."\n"; echo "Get index of element value 11: ".$t->getValueIndex(11)."\n"; ?> Index: pear/Math_Vector/examples/vector_creation.php +++ pear/Math_Vector/examples/vector_creation.php <?php require_once "Math/Vector/Vector.php"; require_once "Math/Vector/Vector2.php"; require_once "Math/Vector/Vector3.php"; $a = range(2,4); $t = new Math_Tuple(array(2,6,8)); echo date("Y-m-d H:i:s")."\n"; echo "==\nVector from array\n"; $v = new Math_Vector($a); echo $v->toString()."\n"; echo "Original length: ".$v->length()."\n"; echo "Converting to a unit vector\n"; $v->normalize(); echo $v->toString()."\n"; echo "Length after normalizing: ".$v->length()."\n"; echo "Reversing vector\n"; $v->reverse(); echo $v->toString()."\n"; echo "==\nVector from tuple\n"; $w = new Math_Vector($t); echo "Distance(v,w) = ".$v->distance($w)."\n"; echo $w->toString()."\n"; echo "==\nVector from another vector\n"; $z = new Math_Vector(new Math_Vector(range(2,5))); echo $z->toString()."\n"; echo "==\nVector3 vector\n"; $x = new Math_Vector3(new Math_Tuple(array(1,0,1))); echo $x->toString()."\n"; echo "==\nVector2 vector\n"; $y = new Math_Vector2(array(1,3)); echo $y->toString()."\n"; echo "==\nInvalid vector\n"; $bar = new Math_Vector("foo"); if ($bar->isValid()) echo "bar is good\n"; else echo "bar is bad\n"; print_r($bar); ?> Index: pear/Math_Vector/examples/vector_operations.php +++ pear/Math_Vector/examples/vector_operations.php <?php require_once "Math/Vector/Vector.php"; require_once "Math/Vector/Vector2.php"; require_once "Math/Vector/Vector3.php"; require_once "Math/Vector/VectorOp.php"; $v1 = new Math_Vector2(array(1,2)); $v2 = new Math_Vector2(array(2,4)); $w1 = new Math_Vector3(array(2,3,1)); $w2 = new Math_Vector3(array(1,-1,0)); $w3 = new Math_Vector3(array(7,3,2)); echo date("Y-m-d H:i:s")."\n"; echo "==\nVector v1: ".$v1->toString()."\n"; echo "Vector v2: ".$v2->toString()."\n"; $r = Math_VectorOp::add($v1, $v2); echo "v1 + v2: ".$r->toString()."\n"; $r = Math_VectorOp::substract($v1, $v2); echo "v1 - v2: ".$r->toString()."\n"; $r = Math_VectorOp::multiply($v1, $v2); echo "v1 * v2: ".$r->toString()."\n"; $r = Math_VectorOp::divide($v1, $v2); echo "v1 / v2: ".$r->toString()."\n"; echo "==\nVector w1: ".$w1->toString()."\n"; echo "Vector w2: ".$w2->toString()."\n"; echo "Vector w3: ".$w3->toString()."\n"; $r = Math_VectorOp::scale(2.0, $w1); echo " 2.0 * w1 = ".$r->toString()."\n"; $r = Math_VectorOp::dotProduct($w1, $w2); echo "w1 . w2 = $r\n"; $r = Math_VectorOp::crossProduct($w2, $w3); echo "w2 x w3 = ".$r->toString()."\n"; echo "The triple scalar product of 3 vectors is the volume of the parallelepiped defined by the vectors. Three coplanar vectors must give a volume of zero, w1, w2 and w3 are coplanar\n"; $r = Math_VectorOp::tripleScalarProduct($w1, $w2, $w3); echo "w1 . (w2 x w3) = $r\n"; $z = Math_VectorOp::createOne(3); echo "Now we introduce z : ".$z->toString()."\n"; echo "and z not being coplanar to w1, w2, or w3:\n"; $r = Math_VectorOp::tripleScalarProduct($z, $w2, $w3); echo "z * (w2 x w3) = $r\n"; $r = Math_VectorOp::angleBetween($z, $w1); echo "and the angle between z and w1 is $r radians\n"; echo "which is ".($r * 180.0/M_PI)." degrees\n"; ?>

« previous php.pear.cvs (#3526) next »