java.lang.Object
java.awt.geom.Line2D
- All Implemented Interfaces:
- Shape, Cloneable
- Direct Known Subclasses:
- Line2D.Double, Line2D.Float
- See Also:
- Top Examples, Source Code
public Object clone()
- See Also:
Cloneable
, OutOfMemoryError
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean contains(double x,
double y)
- See Also:
- Shape
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean contains(double x,
double y,
double w,
double h)
- See Also:
Shape.intersects(double, double, double, double)
, Area
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean contains(Point2D p)
- See Also:
- Shape
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean contains(Rectangle2D r)
- See Also:
Shape.contains(double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public Rectangle getBounds()
- See Also:
Shape.getBounds2D()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract Point2D getP1()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract Point2D getP2()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public PathIterator getPathIterator(AffineTransform at)
- See Also:
- Shape
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public PathIterator getPathIterator(AffineTransform at,
double flatness)
- See Also:
- Shape
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract double getX1()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract double getX2()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract double getY1()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract double getY2()
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean intersects(double x,
double y,
double w,
double h)
- See Also:
Area
, Shape
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean intersects(Rectangle2D r)
- See Also:
Shape.intersects(double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean intersectsLine(double X1,
double Y1,
double X2,
double Y2)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public boolean intersectsLine(Line2D l)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
protected Line2D()
- See Also:
Line2D.Double
, Line2D.Float
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static boolean linesIntersect(double X1,
double Y1,
double X2,
double Y2,
double X3,
double Y3,
double X4,
double Y4)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double ptLineDist(double PX,
double PY)
- See Also:
ptSegDist(double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static double ptLineDist(double X1,
double Y1,
double X2,
double Y2,
double PX,
double PY)
- See Also:
ptSegDist(double, double, double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double ptLineDist(Point2D pt)
- See Also:
ptSegDist(Point2D)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double ptLineDistSq(double PX,
double PY)
- See Also:
ptSegDistSq(double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static double ptLineDistSq(double X1,
double Y1,
double X2,
double Y2,
double PX,
double PY)
- See Also:
ptSegDistSq(double, double, double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double ptLineDistSq(Point2D pt)
- See Also:
ptSegDistSq(Point2D)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double ptSegDist(double PX,
double PY)
- See Also:
ptLineDist(double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static double ptSegDist(double X1,
double Y1,
double X2,
double Y2,
double PX,
double PY)
- See Also:
ptLineDist(double, double, double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
[479]Find square of distance from a point to a line segment
By kebisch { at } lgc { dot } com on 2003/10/29 16:44:35 Rate
// This is C++ , but easily convertible to java .
// Note that it handles both ptSegDist ( ) and ptSegDistSq ( )
#include < math.h >
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
//@ Find square of distance from a point to a line segment.
//@in X1 Abscissa of start point of segment
//@in Y1 Ordinate of start point of segment
//@in X2 Abscissa of end point of segment
//@in Y2 Ordinate of end point of segment
//@in PX Abscissa of point whose distance from segment is to be found.
//@in PY Ordinate of point whose distance from segment is to be found.
double ptSegDistSq ( double X1, double Y1,
double X2, double Y2,
double PX, double PY
)
{
double distSquare ;
double L12Square ;
double X12, Y12, X1P, Y1P, X2P, Y2P ;
// Find vector from ( X1,Y1 ) to ( X2,Y2 )
// and the Square of its length.
X12 = X2 - X1 ;
Y12 = Y2 - Y1 ;
L12Square = X12 * X12 + Y12 * Y12 ;
// Find vector from ( X1,Y1 ) to ( PX,PY ) .
X1P = PX - X1 ;
Y1P = PY - Y1 ;
// Do scalar product and check sign.
if ( X12 * X1P + Y12 * Y1P < = 0.0 )
{
// Closest point on segment is ( X1,Y1 ) ;
// find its distance ( squared ) from ( PX,PY ) .
distSquare = X1P * X1P + Y1P * Y1P ;
}
else
{
// Find vector from ( X2,Y2 ) to ( PX,PY ) .
X2P = PX - X2 ;
Y2P = PY - Y2 ;
// Do scalar product and check sign.
if ( X12 * X2P + Y12 * Y2P > = 0.0 )
{
// Closest point on segment is ( X2,Y2 ) ;
// find its distance ( squared ) from ( PX,PY ) .
distSquare = X2P * X2P + Y2P * Y2P ;
}
else
{
// Closest point on segment is between ( X1,Y1 ) and
// ( X2,Y2 ) . Use perpendicular distance formula.
distSquare = X12 * Y1P - Y12 * X1P ;
distSquare = distSquare * distSquare / L12Square ;
// Note that if L12Square be zero, the first
// of the three branches will be selected,
// so division by zero can not occur here.
}
}
return distSquare ;
}
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
//@ Find distance from a point to a line segment.
//@in X1 Abscissa of start point of segment
//@in Y1 Ordinate of start point of segment
//@in X2 Abscissa of end point of segment
//@in Y2 Ordinate of end point of segment
//@in PX Abscissa of point whose distance from segment is to be found.
//@in PY Ordinate of point whose distance from segment is to be found.
double ptSegDist ( double X1, double Y1,
double X2, double Y2,
double PX, double PY
)
{
return sqrt ( ptSegDistSq ( X1, Y1, X2, Y2, PX, PY ) ) ;
}
// _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
// Test program
#include < iostream.h >
#include < iomanip.h >
#include < fstream.h >
void main ( )
{
ofstream fout ( "distFromSeg.dat" ) ;
double dist ;
double PX ; double PY ;
double X1 = 3 ; double X2 = 7 ;
double Y1 = 5 ; double Y2 = 11 ;
int ix, iy ;
for ( ix = -3; ix < 17; ix++ )
{
PX = ix ; PX = PX + 0.0001 ;
for ( iy = 0; iy < 15; iy++ )
{
PY = iy ; PY = PY + 0.0001 ;
dist = ptSegDist ( X1, Y1, X2, Y2, PX, PY ) ;
cout < < setw ( 15 ) < < setprecision ( 7 ) < < PX
< < setw ( 15 ) < < setprecision ( 7 ) < < PY
< < setw ( 15 ) < < setprecision ( 7 ) < < dist < < endl ;
fout < < setw ( 15 ) < < setprecision ( 7 ) < < PX
< < setw ( 15 ) < < setprecision ( 7 ) < < PY
< < setw ( 15 ) < < setprecision ( 7 ) < < dist < < endl ;
}
}
fout.close ( ) ;
return ;
}
public double ptSegDist(Point2D pt)
- See Also:
ptLineDist(Point2D)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double ptSegDistSq(double PX,
double PY)
- See Also:
ptLineDistSq(double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static double ptSegDistSq(double X1,
double Y1,
double X2,
double Y2,
double PX,
double PY)
- See Also:
ptLineDistSq(double, double, double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public double ptSegDistSq(Point2D pt)
- See Also:
ptLineDistSq(Point2D)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int relativeCCW(double PX,
double PY)
- See Also:
relativeCCW(double, double, double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public static int relativeCCW(double X1,
double Y1,
double X2,
double Y2,
double PX,
double PY)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public int relativeCCW(Point2D p)
- See Also:
relativeCCW(double, double, double, double, double, double)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public abstract void setLine(double X1,
double Y1,
double X2,
double Y2)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setLine(Line2D l)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples
public void setLine(Point2D p1,
Point2D p2)
- Geek's Notes:
- Description Add your codes or notes Search More Java Examples