Java Geometry Algorithm vecLength(final Point2D v)

Here you can find the source of vecLength(final Point2D v)

Description

Calculates the length of a vector.

License

Open Source License

Parameter

Parameter Description
v The vector.

Return

The length of the vector.

Declaration

public static final double vecLength(final Point2D v) 

Method Source Code

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

import java.awt.geom.Point2D;

public class Main {
    /**/*from w  w  w. jav  a 2 s.c o  m*/
     * 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);
    }

    /**
     * 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();
    }
}

Related

  1. slopeOfLineBetween(Point2D.Double p1, Point2D.Double p2)
  2. smallestBoundingBox( java.awt.Point.Double[] points)
  3. snapToGrid(Point original, double gridSpacing)
  4. starRunner(int[][] screen, int x, int y, List blueList)
  5. te static double t(Point2D.Double original, Point2D.Double endpt1, Point2D.Double endpt2)
  6. verticalParallelogram(Point2D top, Point2D bottom, double width)