Package edu.macalester.graphics
Class Point
java.lang.Object
edu.macalester.graphics.Point
A point in two-dimensional space.
This class is immutable. All methods return a new Point.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionTreats the given point like a displacement vector and adds it to the current point.double
angle()
Returns the angle in radians counterclockwise (or clockwise if you view y as up) from the x-axis to this point.static Point
atAngle
(double theta) Returns the unit vector at the given angle in radians.double
Returns the distance between this point and another point.boolean
Two points are equal if they have the same coordinates.double
getX()
The vertical position of this point.double
getY()
The horizontal position of this point.int
hashCode()
static Point
interpolate
(Point p0, Point p1, double alpha) Linearly interpolates by alpha between the two points.double
Returns the distance from this point to the origin.static Point
Returns a point whose x is the maximum of the two given points' x coordinates, and whose y is the maximum of the two given points' y coordinates.static Point
Returns a point whose x is the minimum of the two given points' x coordinates, and whose y is the minimum of the two given points' y coordinates.rotate
(double angle) Returns the point rotated around the origin by the given angle in radians.Returns the point rotated around a given axis point by the given angle in radians.scale
(double s) Multiplies this point's coordinates by a scalar.scale
(double sx, double sy) Multiplies x by sx and y by sy.Treats p like a displacement vector and subtracts it from the current pointConverts this point to the Java AWT Point2D.toString()
withX
(double x) Returns a point with the same y as this one, but a different x.withY
(double y) Returns a point with the same x as this one, but a different y.wrapAround
(Point maxBounds) Makes the coordinates of the input point “wrap around” as if moving in a toroidal space extending from 0 to maxBounds.x, and from 0 to maxBounds.y: coordinates that go off one edge move to the other edge.wrapAround
(Point minBounds, Point maxBounds) Makes the coordinates of the input point “wrap around” as if moving in a toroidal space: coordinates that go off one side move to the other side.
-
Field Details
-
ORIGIN
The point (0,0). -
UNIT_X
The point (1,0). -
UNIT_Y
The point (0,1). -
ONE_ONE
The point (1,1). -
MIN
A point at (-∞,-∞). -
MAX
A point at (∞,∞).
-
-
Constructor Details
-
Point
public Point(double x, double y) Creates a point with the given horizontal and vertical components. -
Point
Converts a Java AWT Point2D to a kilt-graphics Point.
-
-
Method Details
-
atAngle
Returns the unit vector at the given angle in radians. -
getX
public double getX()The vertical position of this point. -
getY
public double getY()The horizontal position of this point. -
withX
Returns a point with the same y as this one, but a different x. -
withY
Returns a point with the same x as this one, but a different y. -
angle
public double angle()Returns the angle in radians counterclockwise (or clockwise if you view y as up) from the x-axis to this point. -
magnitude
public double magnitude()Returns the distance from this point to the origin. -
distance
Returns the distance between this point and another point. -
add
Treats the given point like a displacement vector and adds it to the current point. -
subtract
Treats p like a displacement vector and subtracts it from the current point -
scale
Multiplies this point's coordinates by a scalar. -
scale
Multiplies x by sx and y by sy. -
min
Returns a point whose x is the minimum of the two given points' x coordinates, and whose y is the minimum of the two given points' y coordinates. -
max
Returns a point whose x is the maximum of the two given points' x coordinates, and whose y is the maximum of the two given points' y coordinates. -
wrapAround
Makes the coordinates of the input point “wrap around” as if moving in a toroidal space extending from 0 to maxBounds.x, and from 0 to maxBounds.y: coordinates that go off one edge move to the other edge. Unlike Java’s raw modular arithmetic, this method handles negative values as expected.- Parameters:
maxBounds
- The maximum x and y coordinates- Returns:
- A new Point whose coordinates are each greater than or equal to zero, and less than the coordinates of maxBounds
-
wrapAround
Makes the coordinates of the input point “wrap around” as if moving in a toroidal space: coordinates that go off one side move to the other side. Unlike Java’s raw modular arithmetic, this method handles negative values as expected.- Parameters:
minBounds
- The minimum x and y coordinatesmaxBounds
- The maximum x and y coordinates- Returns:
- A new Point whose coordinates are each greater than or equal to the coordinates of minBounds, and less than the coordinates of maxBounds
-
rotate
Returns the point rotated around the origin by the given angle in radians. -
rotate
Returns the point rotated around a given axis point by the given angle in radians. -
interpolate
Linearly interpolates by alpha between the two points.- Parameters:
p0
- The point for alpha = 0p1
- The point for alpha = 1alpha
- The continuum from p0 to p1
-
equals
Two points are equal if they have the same coordinates. -
hashCode
public int hashCode() -
toString
-
toPoint2D
Converts this point to the Java AWT Point2D.
-