/** * D-function is used to calculate where a point is located in reference to an edge. If the value * is larger than 0 the point is on the left. If it is larger than 0 it's to the right. Equal to 0 * then the point coincides with the edge. Dabp = ((Xa-Xb)*(Ya-Yp)-(Ya-Yb)*(Xa-Xp)) * * @param edge the edge for calculating the D-function * @return D-Function value */ public double dFunction(Edge edge) { double dValue = (edge.getStartPoint().getxCoord() - edge.getEndPoint().getxCoord()) * (edge.getStartPoint().getyCoord() - yCoord) - (edge.getStartPoint().getyCoord() - edge.getEndPoint().getyCoord()) * (edge.getStartPoint().getxCoord() - xCoord); return dValue; }
/** * Calculates the D-Function to check if the coordinate is placed on the edge or not. * * @param edge the edge the point may possibly be on * @return if the point falls on the edge or not */ public boolean dFunctionCheck(Edge edge) { boolean touching = false; double dValue = (edge.getStartPoint().getxCoord() - edge.getEndPoint().getxCoord()) * (edge.getStartPoint().getyCoord() - yCoord) - (edge.getStartPoint().getyCoord() - edge.getEndPoint().getyCoord()) * (edge.getStartPoint().getxCoord() - xCoord); if (Math.abs(dValue) <= round) touching = true; return touching; }
/** * Calculates the shortest distance between this coordinate and the given edge * * @param edge the edge to get the distance to * @return the shortest distance between the edge and this coordinate */ public double shortestDistanceToEdge(Edge edge) { double distanceToStartPoint = distanceTo(edge.getStartPoint()); double anglePointEdge = edge.getStartPoint().calculateAngle(this, edge.getEndPoint()); double shortestDistance = distanceToStartPoint * Math.sin(anglePointEdge); return shortestDistance; }