Java Geometry Algorithm verticalParallelogram(Point2D top, Point2D bottom, double width)

Here you can find the source of verticalParallelogram(Point2D top, Point2D bottom, double width)

Description

Create a parallelogram mostly vertical, where top and bottom sides are short and horizontal.

License

Open Source License

Parameter

Parameter Description
top top point of median line
bottom bottom point of median line
width total width

Return

the created area

Declaration

public static Area verticalParallelogram(Point2D top, Point2D bottom, double width) 

Method Source Code

//package com.java2s;
//  GNU Affero General Public License as published by the Free Software Foundation, either version

import java.awt.geom.Area;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;

public class Main {
    /**/*from  ww  w. jav  a 2s .c om*/
     * Create a parallelogram mostly vertical, where top and bottom sides are short and
     * horizontal.
     * This is most useful for stems.
     * <p>
     * Nota: the defining points are meant to be the extrema points
     * <b>inside</b> the parallelogram.
     *
     * @param top    top point of median line
     * @param bottom bottom point of median line
     * @param width  total width
     * @return the created area
     */
    public static Area verticalParallelogram(Point2D top, Point2D bottom, double width) {
        final double dx = width / 2; // Half width
        final Path2D path = new Path2D.Double();
        path.moveTo(top.getX() - dx, top.getY()); // Upper left
        path.lineTo(top.getX() + dx + 1, top.getY()); // Upper right
        path.lineTo(bottom.getX() + dx + 1, bottom.getY() + 1); // Lower right
        path.lineTo(bottom.getX() - dx, bottom.getY() + 1); // Lower left
        path.closePath();

        return new Area(path);
    }
}

Related

  1. smallestBoundingBox( java.awt.Point.Double[] points)
  2. snapToGrid(Point original, double gridSpacing)
  3. starRunner(int[][] screen, int x, int y, List blueList)
  4. te static double t(Point2D.Double original, Point2D.Double endpt1, Point2D.Double endpt2)
  5. vecLength(final Point2D v)