Java Geometry Algorithm perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)

Here you can find the source of perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)

Description

Computes component of first vector that is perpendicular to the second vector

License

Apache License

Parameter

Parameter Description
projVec first vector
dir vector to project orthogonally to

Return

vector component that is perpendicular to dir

Declaration

public static double perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir) 

Method Source Code


//package com.java2s;
/*/* w ww . ja v  a 2  s  . c  o m*/
 * #%L
 * BlaiseMath
 * --
 * Copyright (C) 2009 - 2015 Elisha Peterson
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.awt.geom.Point2D;
import static java.lang.Math.*;

public class Main {
    /**
     * Computes component of first vector that is perpendicular to the second vector
     * @param projVec first vector
     * @param dir vector to project orthogonally to
     * @return vector component that is perpendicular to <code>dir</code>
     */
    public static double perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir) {
        return Math.sqrt(projVec.distanceSq(0, 0) - pow(scalarProjection(projVec, dir), 2));
    }

    /**
     * Computes scalar projection of first vector onto second vector.
     * @param projVec vector that will be projected
     * @param dir vector to project onto
     * @return length of component of <code>projVec</code> in the direction of <code>dir</code>
     */
    public static double scalarProjection(Point2D.Double projVec, Point2D.Double dir) {
        return dotProduct(projVec, dir) / magnitude(dir);
    }

    /**
     * Computes dot product of two vectors
     * @param v1 first vector
     * @param v2 second vector
     * @return value of dot product
     */
    public static double dotProduct(Point2D.Double v1, Point2D.Double v2) {
        return v1.x * v2.x + v1.y * v2.y;
    }

    /**
     * Computes magnitude of a vector.
     * @param vec the vector
     * @return magnitude
     */
    public static double magnitude(Point2D.Double vec) {
        return vec.distance(0, 0);
    }
}

Related

  1. newZeroPoint()
  2. oneThirdPoint(@Nonnull Point2D pA, @Nonnull Point2D pB)
  3. parabolaByFocusAndDirectrix(Point2D.Double focus, double directrix)
  4. parameterizeCurve(Point[] coefficients, Point startPoint, Point endPoint, Point controlPoint1, Point controlPoint2)
  5. perpendicular(Point a, Point z, double aDist, double size, boolean clockwise)
  6. plotBezier(GeneralPath path, @Nonnull Point2D p0, @Nonnull Point2D p1, @Nonnull Point2D p2, @Nonnull Point2D p3, int depth, double displacement)
  7. plus(Point point1, Point point2)
  8. polarPointAtInfinity(double angle)
  9. polarToPoint(double angle, double fx, double fy)