Calculates the relative orientation of two vectors. - Java java.lang

Java examples for java.lang:Math Vector

Description

Calculates the relative orientation of two vectors.

Demo Code


//package com.java2s;

import java.awt.geom.Point2D;

public class Main {
    /**//from w  w w.jav a 2 s. c o  m
     * Calculates the relative orientation of two vectors.
     * 
     * @param from The starting point of the vector.
     * @param to The vector the orientation is calculated for.
     * @param rel The vector relative to the other.
     * @return {@code > 0} if {@code rel} is left of {@code from -> to} and
     *         {@code < 0} if {@code rel} is right of {@code from -> to}.
     */
    public static int relTo(final Point2D from, final Point2D to,
            final Point2D rel) {
        return (int) Math.signum((to.getX() - from.getX())
                * (from.getY() - rel.getY()) - (rel.getX() - from.getX())
                * (from.getY() - to.getY()));
    }
}

Related Tutorials