MathPHP\LinearAlgebra\Vector::perpendicular PHP Method

perpendicular() public method

[a] [-b] A = [b] A⊥ = [a]
public perpendicular ( ) : Vector
return Vector
    public function perpendicular() : Vector
    {
        if ($this->n !== 2) {
            throw new Exception\VectorException('Perpendicular operation only makes sense for 2D vector. 3D and higher vectors have infinite perpendular vectors.');
        }
        $A⊥ = [-$this->A[1], $this->A[0]];
        return new Vector($A⊥);
    }

Usage Example

コード例 #1
0
ファイル: Vector.php プロジェクト: markrogoyski/math-php
 /**
  * Perpendicular of A on B
  * https://en.wikipedia.org/wiki/Vector_projection#Vector_projection
  *
  *          A⋅B⊥
  * perpᵇA = ---- B⊥
  *          |B|²
  *
  * @param Vector $B
  *
  * @return Vector
  */
 public function perp(Vector $B) : Vector
 {
     $A⋅B⊥ = $B->perpDotProduct($this);
     $│B│² = $B->l2norm() ** 2;
     $B⊥ = $B->perpendicular();
     return $B⊥->scalarMultiply($A⋅B⊥ / $│B│²);
 }