Java Geometry Algorithm dotNorm(final Point2D a, final Point2D b)

Here you can find the source of dotNorm(final Point2D a, final Point2D b)

Description

Calculates the normalized dot product of two vectors.

License

Open Source License

Parameter

Parameter Description
a The first vector.
b The second vector.

Return

The normalized dot product.

Declaration

public static final double dotNorm(final Point2D a, final Point2D b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.geom.Point2D;

public class Main {
    /**/*from  w w w  .j  a v  a  2s .  c o m*/
     * Calculates the normalized dot product of two vectors.
     * {@code a * b / (|a| * |b|)}
     * 
     * @param a
     *            The first vector.
     * @param b
     *            The second vector.
     * @return The normalized dot product.
     */
    public static final double dotNorm(final Point2D a, final Point2D b) {
        return dot(a, b) / (vecLength(a) * vecLength(b));
    }

    /**
     * Calculates the dot product of two vectors.
     * 
     * @param a
     *            The first vector.
     * @param b
     *            The second vector.
     * @return The dot product.
     */
    public static final double dot(final Point2D a, final Point2D b) {
        return a.getX() * b.getX() + a.getY() * b.getY();
    }

    /**
     * Calculates the length of a vector. This operation is relatively
     * expensive. To compare two distances, use {@link #vecLengthSqr(Point2D)}.
     * 
     * @param v
     *            The vector.
     * @return The length of the vector.
     */
    public static final double vecLength(final Point2D v) {
        return Math.sqrt(vecLengthSqr(v));
    }

    /**
     * Calculates the squared length of a vector. This method is much cheaper
     * than {@link #vecLength(Point2D)}.
     * 
     * @param v
     *            The vector.
     * @return The squared length.
     */
    public static final double vecLengthSqr(final Point2D v) {
        return dot(v, v);
    }
}

Related

  1. determineConnectionPoint(Point wayPoint, Polygon polygon)
  2. directVincenty(Point2D.Double point, double brng, double distance)
  3. dot(@Nonnull Point2D pA, @Nonnull Point2D pB)
  4. dot(final Point2D a, final Point2D b)
  5. dot(Point a, Point b, Point c)
  6. drag(Robot robot, Point startPoint, Point endPoint, int button)
  7. dx(Point a, Point b)
  8. edge(Collection points)
  9. extendLine(Point2D p0, Point2D p1, double toLength)