|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Object | +--com.jfimagine.jfgraph.geom.LineSeg
LineSeg class. A class used to represent a line in the plane with double coordinates.
Attention: Here we used a clockwise quadrant system. And the first quadrant is under right bottom corner.
| Constructor Summary | |
LineSeg()
Constructor for LineSeg. |
|
LineSeg(double x1,
double y1,
double x2,
double y2)
Constructor for LineSeg. |
|
LineSeg(JFPoint startPoint,
JFPoint endPoint)
Constructor for LineSeg. |
|
LineSeg(LineSeg lineSeg)
Constructor for LineSeg. |
|
| Method Summary | |
java.lang.Object |
clone()
Creates a new object of the same class and with the same contents as this object. |
JFPoint |
closeTo(double px,
double py)
Returns a closest point on this line segment to specified point. |
boolean |
contains(double x,
double y)
Test if a point(x, y coordinates for instead) is on this line. |
boolean |
contains(double x,
double y,
double pickOffset)
Test if a point(x, y coordinates for instead) is on this line. |
boolean |
contains(JFPoint pnt)
Test if a point is on this line. |
boolean |
contains(JFPoint pnt,
double pickOffset)
Test if a point is on this line. |
double |
distance(double px,
double py)
Returns the distance from a point to this line segment. |
double |
distance(JFPoint pnt)
Returns the distance from a point to this line segment. |
boolean |
equals(java.lang.Object obj)
Determines whether or not two objects are equal. |
void |
flipBy()
Reverse this line by a central y coordinate of this line. |
void |
flipBy(double baseY)
Reverse this line by a y coordinate. |
Rect |
getBounds()
Get the bounds of this line segment. |
JFPoint |
getCenter()
Get a center point on this line. |
double |
getLength()
Get the length of this line. |
static double |
getLength(double x1,
double y1,
double x2,
double y2)
Get the length between two endpoints of a line. |
static double |
getLength(JFPoint pnt1,
JFPoint pnt2)
Get the length between two endpoints of a line. |
JFPoint |
getPoint1()
Get point1, i.e. the point at x1,y1 |
JFPoint |
getPoint2()
Get point2, i.e. the point at x2,y2 |
double |
getSlope()
Get the slope of this line. |
static double |
getSlope(double x1,
double y1,
double x2,
double y2)
Get the slope of a specified line. |
static double |
getSlope(JFPoint startPoint,
JFPoint endPoint)
Get the slope of a specified line. |
static double |
getSlope(LineSeg line)
Get the slope of a specified line. |
double |
getX1()
Get x coordiate of first endpoint. |
double |
getX2()
Get x coordiate of second endpoint. |
double |
getY1()
Get y coordiate of first endpoint. |
double |
getY2()
Get y coordiate of second endpoint. |
int |
hashCode()
Returns the hashcode for this Object. |
boolean |
intersects(double x1,
double y1,
double x2,
double y2)
Tests if the specified line segment intersects this LineSeg. |
boolean |
intersects(JFPoint startPoint,
JFPoint endPoint)
Tests if the specified line segment intersects this LineSeg. |
boolean |
intersects(LineSeg l)
Tests if the specified line segment intersects the this LineSeg. |
boolean |
intersects(Rect rect)
Tests if the specified rectangle intersects the interior of this LineSeg. |
JFPoint |
intersectsAt(double x1,
double y1,
double x2,
double y2)
Get an intersected point both on this line and a new line. |
JFPoint |
intersectsAt(JFPoint startPoint,
JFPoint endPoint)
Get an intersected point both on this line and a new line. |
void |
mirrorBy()
Mirror this line by a central x coordinate of this line. |
void |
mirrorBy(double baseX)
Mirror this line by a x coordinate. |
void |
moveBy(double x,
double y)
Move this line by specific x and y coordinates. |
void |
rotateBy(double theta)
Rotate this line by an angle theta. |
void |
rotateBy(double baseX,
double baseY,
double theta)
Rotate this line by a specified point and an angle theta. |
void |
rotateBy(JFPoint pnt,
double theta)
Rotate this line by a specified point and an angle theta. |
static boolean |
sameLinePoints(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Test if three points are on same line. |
static boolean |
sameLinePoints(JFPoint point1,
JFPoint point2,
JFPoint point3)
Test if three points are on same line. |
void |
scaleBy(double scale)
Scale this line by its center point, and specified scale. |
void |
scaleBy(double baseX,
double baseY,
double scale)
Scale this line by a point, and specified scale. |
void |
scaleBy(double baseX,
double baseY,
double xScale,
double yScale)
Scale this line by a point, and specified scale. |
void |
scaleBy(JFPoint basePoint,
JFPoint refPoint1,
JFPoint refPoint2,
double scale)
Scale current rectangle by specified points and scale percent. |
void |
setPoint1(double x,
double y)
Set point1, i.e. the point at x1,y1 |
void |
setPoint1(JFPoint pnt)
Set point1, i.e. the point at x1,y1 |
void |
setPoint2(double x,
double y)
Set point2, i.e. the point at x2,y2 |
void |
setPoint2(JFPoint pnt)
Set point2, i.e. the point at x2,y2 |
void |
setValue(double x1,
double y1,
double x2,
double y2)
Set a line's value by two points. |
void |
setValue(JFPoint point1,
JFPoint point2)
Set a line's value by two points. |
void |
setValue(LineSeg line)
Set a line's value by a line segment. |
void |
setX1(double val)
Set x coordiate of first endpoint. |
void |
setX2(double val)
Set x coordiate of second endpoint. |
void |
setY1(double val)
Set y coordiate of first endpoint. |
void |
setY2(double val)
Set y coordiate of second endpoint. |
java.lang.String |
toString()
Convert this object to String |
JFPoint |
uprightFoot(double px,
double py)
Returns an upright foot point on this line segment to specified point. |
static JFPoint |
uprightFoot(double slope,
double x1,
double y1,
double px,
double py)
Returns an upright foot point on a specified slope of a line accross a specified point. |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public LineSeg()
public LineSeg(double x1,
double y1,
double x2,
double y2)
public LineSeg(JFPoint startPoint,
JFPoint endPoint)
startPoint - The first endpoint.endPoint - The second endpoint.public LineSeg(LineSeg lineSeg)
lineSeg - A JFLine Segment.| Method Detail |
public double getX1()
public void setX1(double val)
val - A new x coordiate of first endpoint.public double getY1()
public void setY1(double val)
val - A new y coordiate of first endpoint.public double getX2()
public void setX2(double val)
val - A new x coordiate of second endpoint.public double getY2()
public void setY2(double val)
val - A new y coordiate of second endpoint.public JFPoint getPoint1()
public void setPoint1(JFPoint pnt)
pnt - A new point.
public void setPoint1(double x,
double y)
public JFPoint getPoint2()
public void setPoint2(JFPoint pnt)
pnt - A new point.
public void setPoint2(double x,
double y)
public void setValue(LineSeg line)
public void setValue(JFPoint point1,
JFPoint point2)
point1 - The start pointpoint2 - The end point
public void setValue(double x1,
double y1,
double x2,
double y2)
public Rect getBounds()
public double getLength()
public static double getLength(JFPoint pnt1,
JFPoint pnt2)
pnt1 - One endpoint of the line.pnt2 - Other endpoint of the line.
public static double getLength(double x1,
double y1,
double x2,
double y2)
public void moveBy(double x,
double y)
x - X coordiate to moveby.y - Y coordiate to moveby.public JFPoint getCenter()
public void rotateBy(double theta)
theta - A rotate angle.
public void rotateBy(JFPoint pnt,
double theta)
pnt - A rotate center point.theta - A rotate angle.
public void rotateBy(double baseX,
double baseY,
double theta)
theta - A rotate angle.public void mirrorBy()
public void mirrorBy(double baseX)
baseX - A mirror base x coordinate.public void flipBy()
public void flipBy(double baseY)
baseY - A flip base y coordinate.
public void scaleBy(JFPoint basePoint,
JFPoint refPoint1,
JFPoint refPoint2,
double scale)
basePoint - A base point that is unmovable.refPoint1 - A 'width' reference point.refPoint2 - A 'height' reference point.scale - A reference scale percent.public void scaleBy(double scale)
scale - A scale value.
public void scaleBy(double baseX,
double baseY,
double scale)
scale - A scale value.
public void scaleBy(double baseX,
double baseY,
double xScale,
double yScale)
xScale - A scale value in x coordinate.yScale - A scale value in y coordinate.public boolean contains(JFPoint pnt)
pnt - A point to be measured.
public boolean contains(JFPoint pnt,
double pickOffset)
pnt - A point to be measured.pickOffset - An analog offset for 'pick' this line.
public boolean contains(double x,
double y)
x - X coordinate of this point.y - Y coordinate of this point.
public boolean contains(double x,
double y,
double pickOffset)
x - X coordinate of this point.y - Y coordinate of this point.
public static boolean sameLinePoints(JFPoint point1,
JFPoint point2,
JFPoint point3)
point1 - first point one the line.point2 - second point one the linepoint3 - third point one the line
public static boolean sameLinePoints(double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
public double distance(JFPoint pnt)
pnt - the specified point being
measured against the specified line segment
public double distance(double px,
double py)
public JFPoint closeTo(double px,
double py)
public JFPoint uprightFoot(double px,
double py)
public static JFPoint uprightFoot(double slope,
double x1,
double y1,
double px,
double py)
slope - A slope of a line.
public boolean intersects(LineSeg l)
LineSeg.
l - the specified LineSeg to test for intersection
with this LineSeg
true if the specified LineSeg
intersects this LineSeg;
false otherwise.
public boolean intersects(JFPoint startPoint,
JFPoint endPoint)
LineSeg.
startPoint - the first endpoint of the specified
line segmentendPoint - the second endpoint of the specified
line segment
true if the specified line segment intersects
the this LineSeg; false
otherwise.
public boolean intersects(double x1,
double y1,
double x2,
double y2)
LineSeg.
true if the specified line segment intersects
the this LineSeg; false
otherwise.public boolean intersects(Rect rect)
LineSeg.
rect - the specified Rect to test for intersection
with the interior of this LineSeg
true if the specified Rect
intersects the interior of this LineSeg;
false otherwise.public double getSlope()
public static double getSlope(LineSeg line)
line - A line for test slope.
public static double getSlope(JFPoint startPoint,
JFPoint endPoint)
startPoint - one end point of the line.endPoint - the other end point of the line.
public static double getSlope(double x1,
double y1,
double x2,
double y2)
public JFPoint intersectsAt(JFPoint startPoint,
JFPoint endPoint)
startPoint - the first endpoint of the specified
line segmentendPoint - the second endpoint of the specified
line segment
public JFPoint intersectsAt(double x1,
double y1,
double x2,
double y2)
If we know two points on a line (x1,y1) and (x2,y2), we can determine m and b as follows. From its definition, m = change in y divided by change in x = (y2-y1)/(x2-x1). And since b=y-mx for any point on the line, we can compute b1=y1-mx1.
With two line segments, we can derive an equation for each, say y=m1x+b1 and y=m2x+b2. The x and y values at the intersection point must satisfy both, so y = m1x+b1=m2x+b2. If we take the last half of this and solve for x, we get m1x+b1=m2x+b2, or (m1-m2)x=b2-b1 or x=(b2-b1)/(m1-m2). Notice that when m1 equals m2, the lines are parallel and they will never intersect. The final test is to see if the intersection point is between the endpoints of each line segment. This just involves making sure that our x is greater than (or equal to) the smallest x endpoint value and smaller than (or equal to) the largest endpoint x value for each line.
public java.lang.String toString()
toString in class java.lang.Object
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class java.lang.Objectjava.lang.CloneNotSupportedExceptionpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - an object to be compared with this object
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||