Java Geometry Algorithm relTo(final Point2D from, final Point2D to, final Point2D rel)

Here you can find the source of relTo(final Point2D from, final Point2D to, final Point2D rel)

Description

Calculates the relative orientation of two vectors.

License

Open Source License

Parameter

Parameter Description
from The starting point of the vector.
to The vector the orientation is calculated for.
rel The vector relative to the other.

Return

> 0 if rel is left of from -> to and < 0 if rel is right of from -> to .

Declaration

public static final int relTo(final Point2D from, final Point2D to, final Point2D rel) 

Method Source Code

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

import java.awt.geom.Point2D;

public class Main {
    /**//from ww  w. j  a  va  2 s .  com
     * 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 final 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

  1. project(Point2D.Double sourceLocation, double angle, double length)
  2. projectionFactor(Point pt, Point start, Point stop)
  3. projectPoint(float x, float y, Line2D ray, float distance)
  4. projectPointOntoLine(Point2D pt, Line2D ln)
  5. quantisePoint(Point2D.Double dpos, Point gpos)
  6. resample(Vector points, int n, Vector newPoints)
  7. setPathAnchor(Shape s, Point2D pt)
  8. setPathControlPoint(Shape s, int i, Point2D pt)
  9. setRevisePoint(Point2D.Double revisePoint, Point2D.Double startPoint)