Generates a vector pointing in the opposite direction. - Java java.lang

Java examples for java.lang:Math Vector

Description

Generates a vector pointing in the opposite direction.

Demo Code


//package com.java2s;

import java.awt.geom.Point2D;

public class Main {
    /**//  www .j a v  a2s  . c om
     * Generates a vector pointing in the opposite direction.
     * 
     * @param v The vector.
     * @return The inverse vector.
     */
    public static Point2D invVec(final Point2D v) {
        return mulVec(v, -1.0);
    }

    /**
     * Multiplies a point with a scalar.
     * 
     * @param a The point.
     * @param scalar The scalar.
     * @return the scaled version.
     */
    public static Point2D mulVec(final Point2D a, final double scalar) {
        return new Point2D.Double(a.getX() * scalar, a.getY() * scalar);
    }
}

Related Tutorials