Here you can find the source of perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)
Parameter | Description |
---|---|
projVec | first vector |
dir | vector to project orthogonally to |
dir
public static double perpendicularScalarProjection(Point2D.Double projVec, Point2D.Double dir)
//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); } }