diff options
author | Kore Nordmann <github@kore-nordmann.de> | 2007-02-01 10:02:58 +0000 |
---|---|---|
committer | Kore Nordmann <github@kore-nordmann.de> | 2007-02-01 10:02:58 +0000 |
commit | ecef8638e0f565059960214f384430b07ce723a2 (patch) | |
tree | be37fe9bd1e8a6389a9f34ea6e454f7fdfaacf2a /src/math | |
parent | 70151cd3ac52bb8ea3b854adcc7bfc38524d0b36 (diff) | |
download | zetacomponents-graph-ecef8638e0f565059960214f384430b07ce723a2.zip zetacomponents-graph-ecef8638e0f565059960214f384430b07ce723a2.tar.gz |
- Added and test method to receive angle between two vectors
Diffstat (limited to 'src/math')
-rw-r--r-- | src/math/vector.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/math/vector.php b/src/math/vector.php index 85832bb..f6f7af5 100644 --- a/src/math/vector.php +++ b/src/math/vector.php @@ -102,6 +102,26 @@ class ezcGraphVector extends ezcGraphCoordinate } /** + * Returns the angle between two vectors in radian + * + * @param ezcGraphCoordinate $vector + * @return float + */ + public function angle( ezcGraphCoordinate $vector ) + { + if ( !$vector instanceof ezcGraphVector ) + { + // Ensure beeing a vector for calling length() + $vector = ezcGraphVector::fromCoordinate( $vector ); + } + + return acos( + $this->mul( $vector ) / + ( $this->length() * $vector->length() ) + ); + } + + /** * Adds a vector to another vector * * @param ezcGraphCoordinate $vector |