Package com.dkt.graphics.elements
Class GLine
java.lang.Object
com.dkt.graphics.elements.GraphicE
com.dkt.graphics.elements.GLine
- All Implemented Interfaces:
Cloneable
This class represents a line segment
- Author:
- Federico Vera <[email protected]>
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionGLine(int x, int y, double length, double angle) Constructs a new line based on its start point, length and angleGLine(int x1, int y1, int x2, int y2) Constructs a new line segment based on the end pointsCopy constructorConstructs a new line segment based on the end points -
Method Summary
Modifier and TypeMethodDescriptionclone()booleancontains(int x, int y) Tells if a point is contained in this line segmentbooleanTells if a point is contained in this line segmentvoiddraw(Graphics2D g) Draws the component on the given graphicsbooleandoubleRetrieves the argument of the line segment (in degrees)Retrieves a copy of the end point of this line segmentRetrieves the middle point of the lineRetrieves an orthogonal line that segment contains (0, 0) as it's start pointgetOrthogal(int x, int y) Retrieves an orthogonal line segment that contains (x, y) as it's start pointgetParallel(int x, int y) Retrieves an parallel line segment that contains (x, y) as it's start pointdoubleRetrieves the argument of the line segment (in radians)Retrieves a copy of the start point of this line segmentinthashCode()doublemodulus()Retrieves the length of the line segmentvoidtraslate(int x, int y) Traslates this element on X and Y
-
Constructor Details
-
GLine
Copy constructor- Parameters:
e-GLineto copy- Throws:
IllegalArgumentException- ifeisnull
-
GLine
Constructs a new line segment based on the end points- Parameters:
p1- start pointp2- end point- Throws:
IllegalArgumentException
-
GLine
public GLine(int x1, int y1, int x2, int y2) Constructs a new line segment based on the end points- Parameters:
x1- x coordinate of the start pointy1- y coordinate of the start pointx2- x coordinate of the end pointy2- y coordinate of the end point
-
GLine
public GLine(int x, int y, double length, double angle) Constructs a new line based on its start point, length and angle- Parameters:
x- x coordinate of the start pointy- y coordinate of the start pointlength- length of the vectorangle- angle (in degrees) of the line segment
-
-
Method Details
-
getMiddlePoint
Retrieves the middle point of the line- Returns:
- middle point
-
getOrthogal
Retrieves an orthogonal line that segment contains (0, 0) as it's start point- Returns:
- Orthogonal
GLine
-
getOrthogal
Retrieves an orthogonal line segment that contains (x, y) as it's start point- Parameters:
x- x coordinate of the start pointy- y coordinate of the start point- Returns:
- Orthogonal
GLine
-
getParallel
Retrieves an parallel line segment that contains (x, y) as it's start point- Parameters:
x- x coordinate of the start pointy- y coordinate of the start point- Returns:
- Orthogonal
GLine
-
getStartPoint
Retrieves a copy of the start point of this line segment- Returns:
- start
GPointof the line segment
-
getEndPoint
Retrieves a copy of the end point of this line segment- Returns:
- end
GPointof the line segment
-
getRadArgument
public double getRadArgument()Retrieves the argument of the line segment (in radians)- Returns:
- angle in radians
-
getArgument
public double getArgument()Retrieves the argument of the line segment (in degrees)- Returns:
- angle in degrees
-
modulus
public double modulus()Retrieves the length of the line segment- Returns:
- length
-
contains
Tells if a point is contained in this line segment- Parameters:
p- point to check- Returns:
trueif the point is contained in the segment andfalseotherwise- Throws:
IllegalArgumentException- ifpisnull
-
contains
public boolean contains(int x, int y) Tells if a point is contained in this line segment- Parameters:
x- the X coordinate of the pointy- the Y coordinate of the point- Returns:
trueif the point is contained in the segment andfalseotherwise
-
draw
Description copied from class:GraphicEDraws the component on the given graphics -
traslate
public void traslate(int x, int y) Description copied from class:GraphicETraslates this element on X and Y -
clone
-
hashCode
public int hashCode() -
equals
-