/** * Get the coordinates of the second vertex of the indexed edge * * @param start * the index of the edge * @return the second vertex, going clockwise */ public RealLocalizable getEdgeEnd( final int start ) { return getEdgeStart( start + 1 ); }
/** * Determine whether the given edge is horizontal. If so, * interpolateEdgeXAtY won't work because the X is then indeterminate. * * @param index * index of edge to examine * @return true if horizontal (Y coordinates of start and end are identical) */ public boolean isHorizontal( final int index ) { return getEdgeStart( index ).getDoublePosition( 1 ) == getEdgeEnd( index ).getDoublePosition( 1 ); }
for ( int i = 0; i < getVertexCount(); i++ ) final double y_start = getEdgeStart( i ).getDoublePosition( 1 ); final double y_end = getEdgeEnd( i ).getDoublePosition( 1 ); final double x_start = getEdgeStart( i ).getDoublePosition( 0 ); final double x_end = getEdgeEnd( i ).getDoublePosition( 0 ); if ( y_start == y_end )
final RealLocalizable p0 = getEdgeStart( i ); final RealLocalizable p1 = getEdgeEnd( i ); double x0 = p0.getDoublePosition( 0 );
/** * Given an edge and a Y coordinate, find its X coordinate at that Y * coordinate. * * NOTE: this assumes that isHorizontal(start) is false, else the X * coordinate is indeterminate. * * @param start * index of the edge * @return the X coordinate */ public double interpolateEdgeXAtY( final int start, final double y ) { final RealLocalizable p_start = getEdgeStart( start ); final RealLocalizable p_end = getEdgeEnd( start ); final double x_start = p_start.getDoublePosition( 0 ); final double y_start = p_start.getDoublePosition( 1 ); final double x_end = p_end.getDoublePosition( 0 ); final double y_end = p_end.getDoublePosition( 1 ); return x_start + ( y - y_start ) * ( x_end - x_start ) / ( y_end - y_start ); }