Class Geom

java.lang.Object
eu.bandm.tools.graficUtils.Geom

public class Geom extends Object
Provides static methods for geometrical calculations
  • Method Details

    • pointd2point

      public static Point pointd2point(Point2D dp)
      convert a Point2D to a Point
    • point2pointd

      public static Point2D.Double point2pointd(Point2D p)
      convert a Point2D to a Point2D.Double
    • movePoint

      public static Point2D.Double movePoint(Point2D p, int dx, int dy)
      Add a difference vector to a point.
    • movePoint

      public static Point2D.Double movePoint(Point2D p, double dx, double dy)
      Add a difference vector to a point.
    • center

      public static Point2D.Double center(Point2D p1, Point2D p2)
      Find the center between two points.
    • rectangle_x1

      public static double rectangle_x1(Rectangle2D rect)
      Get the lower x coordinate of a Rectangle2D
    • rectangle_x2

      public static double rectangle_x2(Rectangle2D rect)
      Get the upper x coordinate of a Rectangle2D
    • rectangle_y1

      public static double rectangle_y1(Rectangle2D rect)
      Get the lower y coordinate of a Rectangle2D
    • rectangle_y2

      public static double rectangle_y2(Rectangle2D rect)
      Get the upper y coordinate of a Rectangle2D
    • rectangle_p1

      public static Point2D.Double rectangle_p1(Rectangle2D rect)
      Get the lower left point of a Rectangle2D
    • rectangle_p2

      public static Point2D.Double rectangle_p2(Rectangle2D rect)
      Get the upper right point of a Rectangle2D
    • findEdgeOrCorner

      public static int findEdgeOrCorner(Rectangle2D rect, Point2D p, double eps)
      Find the edge or corner of a given rectangle, the given point is part of.

      The returned result is an int index according to the following number assignment:
              3=nw  2=n   1=ne
                +--------+
                |      p2|
           4=w  |        |  0=e
                |p1      |
                +--------+
              5=sw  6=s   7=se
        
      
      Parameters:
      rect - the rectangle
      p - the point
      eps - the granularity of the equality test
      Returns:
      number code, as above, or -1 if no hit.
    • connectCenters

      public static Line2D.Double connectCenters(Rectangle2D from, Rectangle2D to, int xoff, int yoff)
      Calculate the segment of the straight line connecting the centers of two rectangles which end at their borders.
      This can be depicted as
                            +---------+
                            |    * pt |
                            +---. --- +
                              /
                            /
                          /
                        / 
           +---------+/
           |        .|
           |      .  |
           |    *    |
           |    pf   |
           |         |
           +-------- +
      

      Additionally, the reference points can be shifted out of the centers by a per-axis offset.
      Parameters:
      from - one rectangle
      to - the other
      xoff - offset to the x coordinate, for both points
      yoff - offset to the y coordinate, for both points
    • calcCut

      protected static Point2D.Double calcCut(double tan, double centerx, double centery, double limitx, double limity)
      calculate:
                         
                            |    *    
                            +---. --- +
                              /
                            /
      
           == OR ==
                        / 
            ---------+/
                    .|
                  .  |
          |
      
           
    • arrowEdges

      public static Line2D.Double arrowEdges(Point2D arrowpoint, Point2D comesfrom, double len, double width)
      Calculate points for drawing arrow heads.
                              /
                      p1     /
                      |.    /
                      | .  / w
                      |  ./   i 
                      |  /p0   d 
                      | /=len .  t
                      |/        .  h 
                      v----------p2
                        =len
      
      
      (The algorithm is "analytical" and does not employ trigonometric functions !-)
      Parameters:
      arrowpoint - where the tip of the arrowhead lies.
      comesfrom - the other point of the line
      len - the length of the arrowline which falls into the head.
      width - the opening width of half the arrow head (VERIFY FIXME ??)
      Returns:
      the line which connects the two points of the head != arrowpoint
    • towardsPoint

      public static Point2D.Double towardsPoint(Point2D from, double len, Point2D to)
    • MOVE

      protected static void MOVE(GeneralPath gp, Point2D p)
    • LINE

      protected static void LINE(GeneralPath gp, Point2D p)
    • SPLINE

      protected static void SPLINE(GeneralPath gp, Point2D paux, Point2D p)
    • makeRoundedPath

      @Opt public static @Opt GeneralPath makeRoundedPath(double radius, double eps_collinear, Point2D... points0)
      Creates a path with rounded edges which connect the given points.
      Parameters:
      radius - the radius of the rounded edges
      eps_collinear - when two lines are considered "not an edge"
      points0 - the sequence of points.
    • makeDiamond

      public static GeneralPath makeDiamond(Rectangle2D rect)
      Deliver a path wich connects the centers of the borders of the rectangle
       +------+
       |  /\  |
       | /  \ |
       |/    \|
       |\    /|
       | \  / |
       |  \/  |
       +------+
      
    • makeSquare

      public static GeneralPath makeSquare(float cx, float cy, float radius)
    • makeSquare

      public static GeneralPath makeSquare(Point2D center, float radius)
    • transposeCoordinate

      public static float transposeCoordinate(float coordinate, float sourcemin, float sourcemax, float targetmin, float targetmax)