Package pointgon

Class Vertex

java.lang.Object
pointgon.Vertex
All Implemented Interfaces:
Serializable, Comparable<Vertex>

public class Vertex extends Object implements Comparable<Vertex>, Serializable
Class for vertices (perimeter and holes) of a pointgon.
Since:
2005.02.18 (Christian Borgelt)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
    vertex identifier
    double
    x-coordinate of vertex
    double
    y-coordinate of vertex
  • Constructor Summary

    Constructors
    Constructor
    Description
    Vertex(double x, double y)
    Create a vertex.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compare this vertex to another.
    double
    distance(double x, double y)
    Compute the distance to a given point.
    double
    Compute the distance to a given vertex.
    int
    Check whether a horizontal line through the vertex cuts an edge.
    boolean
    isects(double dx, double dy, Vertex src, Vertex dst)
    Check whether a line through the vertex cuts an edge.
    boolean
    isects(Vertex to, Edge edge)
    Check whether a line through the vertex cuts an edge.
    boolean
    isects(Vertex to, Vertex src, Vertex dst)
    Check whether a line through the vertex cuts an edge.
    boolean
    isectsX(Vertex to, Edge edge)
    Check whether a line through the vertex cuts an edge.
    boolean
    isectsX(Vertex to, Vertex src, Vertex dst)
    Check whether a line through the vertex cuts an edge.
    boolean
    Check whether the vertex is inside a triangle.
    boolean
    Check whether the vertex is inside a triangle.
    boolean
    isLeftOf(Edge edge)
    Check the position of the vertex relative to an edge.
    boolean
    isLeftOf(Vertex src, Vertex dst)
    Check the position of the vertex relative to an edge.
    boolean
    isPartOf(Edge edge)
    Check the position of the vertex relative to an edge.
    boolean
    isPartOf(Vertex src, Vertex dst)
    Check the position of the vertex relative to an edge.
    boolean
    Check the position of the vertex relative to an edge.
    boolean
    isRightOf(Vertex src, Vertex dst)
    Check the position of the vertex relative to an edge.
    int
    sideOf(Vertex src, Vertex dst)
    Check the position of the vertex relative to an edge.
    Create a string description of the vertex.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • id

      public int id
      vertex identifier
    • x

      public double x
      x-coordinate of vertex
    • y

      public double y
      y-coordinate of vertex
  • Constructor Details

    • Vertex

      public Vertex(double x, double y)
      Create a vertex.
      Parameters:
      x - the x-coordinate of the vertex
      y - the y-coordinate of the vertex
      Since:
      2005.02.18 (Christian Borgelt)
  • Method Details

    • distance

      public double distance(double x, double y)
      Compute the distance to a given point.
      Parameters:
      x - the x-coordinate of the point
      y - the y-coordinate of the point
      Returns:
      the distance to the given point
      Since:
      2005.02.18 (Christian Borgelt)
    • distance

      public double distance(Vertex v)
      Compute the distance to a given vertex.
      Parameters:
      v - the vertex to compute the distance to
      Returns:
      the distance to the given vertex
      Since:
      2005.02.18 (Christian Borgelt)
    • sideOf

      public int sideOf(Vertex src, Vertex dst)
      Check the position of the vertex relative to an edge.
      Parameters:
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      -1, if the vertex is in the left, +1, if the vertex is on the right, and 0 if the vertex is on the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isLeftOf

      public boolean isLeftOf(Vertex src, Vertex dst)
      Check the position of the vertex relative to an edge.
      Parameters:
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      whether the vertex os to the left of the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isLeftOf

      public boolean isLeftOf(Edge edge)
      Check the position of the vertex relative to an edge.
      Parameters:
      edge - the edge to check
      Returns:
      whether the vertex os to the left of the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isRightOf

      public boolean isRightOf(Vertex src, Vertex dst)
      Check the position of the vertex relative to an edge.
      Parameters:
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      whether the vertex is to the right of the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isRightOf

      public boolean isRightOf(Edge edge)
      Check the position of the vertex relative to an edge.
      Parameters:
      edge - the edge to check
      Returns:
      whether the vertex is to the right of the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isPartOf

      public boolean isPartOf(Vertex src, Vertex dst)
      Check the position of the vertex relative to an edge.
      Parameters:
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      whether the vertex is on the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isPartOf

      public boolean isPartOf(Edge edge)
      Check the position of the vertex relative to an edge.
      Parameters:
      edge - the edge to check
      Returns:
      whether the vertex is on the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isInside

      public boolean isInside(Vertex a, Vertex b, Vertex c)
      Check whether the vertex is inside a triangle.
      Parameters:
      a - the first vertex of the triangle
      b - the second vertex of the triangle
      c - the third vertex of the triangle
      Returns:
      whether the vertex is inside the triangle
      Since:
      2005.02.18 (Christian Borgelt)
    • isInsideX

      public boolean isInsideX(Vertex a, Vertex b, Vertex c)
      Check whether the vertex is inside a triangle.

      (check both orders of the triangle corners)

      Parameters:
      a - the first vertex of the triangle
      b - the second vertex of the triangle
      c - the third vertex of the triangle
      Returns:
      whether the vertex is inside the triangle
      Since:
      2005.02.18 (Christian Borgelt)
    • horzLineCuts

      public int horzLineCuts(Vertex src, Vertex dst)
      Check whether a horizontal line through the vertex cuts an edge.
      Parameters:
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      whether the line cuts the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isects

      public boolean isects(double dx, double dy, Vertex src, Vertex dst)
      Check whether a line through the vertex cuts an edge.
      Parameters:
      dx - the x-coordinate of the direction vector of the line
      dy - the y-coordinate of the direction vector of the line
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      whether the line cuts the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isects

      public boolean isects(Vertex to, Vertex src, Vertex dst)
      Check whether a line through the vertex cuts an edge.
      Parameters:
      to - the vertex the line leads to (from this vertex)
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      whether the line cuts the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isects

      public boolean isects(Vertex to, Edge edge)
      Check whether a line through the vertex cuts an edge.
      Parameters:
      to - the vertex the line leads to (from this vertex)
      edge - the edge to check
      Returns:
      whether the line cuts the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isectsX

      public boolean isectsX(Vertex to, Vertex src, Vertex dst)
      Check whether a line through the vertex cuts an edge.
      Parameters:
      to - the vertex the line leads to (from this vertex)
      src - the first vertex of the edge
      dst - the second vertex of the edge
      Returns:
      whether the line cuts the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • isectsX

      public boolean isectsX(Vertex to, Edge edge)
      Check whether a line through the vertex cuts an edge.
      Parameters:
      to - the vertex the line leads to (from this vertex)
      edge - the edge to check
      Returns:
      whether the line cuts the edge
      Since:
      2005.02.18 (Christian Borgelt)
    • compareTo

      public int compareTo(Vertex obj)
      Compare this vertex to another.
      Specified by:
      compareTo in interface Comparable<Vertex>
      Parameters:
      obj - the other vertex
      Returns:
      the sign of the coordinate difference (x-coordinate takes precedence over y-coordinate)
      Since:
      2005.02.18 (Christian Borgelt)
    • toString

      public String toString()
      Create a string description of the vertex.
      Overrides:
      toString in class Object
      Returns:
      the created string description
      Since:
      2005.02.18 (Christian Borgelt)