Class Circle
- All Implemented Interfaces:
Shape
public class Circle extends java.lang.Object implements Shape
Circles are a lot more complex mathematically than their linear counterparts. I'm writing a lot of code that doesn't really do much right now and I'm not near any pencils and paper so I don't feel like working out the math to figure out how to detect things like line-circle collisions and even circle-circle collisions, but I'm sure I'll get around to that somewhere in the near enough future.
If you'll notice, this circle actually has two component circles contained within it - one labelled "circle," and the other; "hitbox." My reasoning behind doing this has nothing to do with liking to type out GigaArc (GigaArc GigaArc GigaArc GigaArc GigaArc GigaArc) and more to do with the fact that circles are a tad bit finicky and I have a feeling the hitbox might come in handy for future collision detection (and hopefully avoidance).
Note that circles are a lot less expensive than rectangles and they have significantly fewer components. If you have a situation in which a circle could serve as a substitute for a rectangle...
- Since:
- 0.1.0
- Author:
- Colin Robertson
-
Field Summary
Fields Modifier and Type Field Description Point
center
The center-point of the circle.private GigaArc
circle
The internal component for the circle.private GigaArc
hitbox
The internal component for the circle's hitbox.double
hitboxRadius
The radius of the circle's hitbox.double
radius
The radius of the circle itself. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
doesLineIntersectWithCircle(Line line)
A method to determine whether or not a line intersects with a circle.int
getComponents()
Get a count of the components in the circle.boolean
isLineInShape(Line line)
Check whether or not a line enters a shape.boolean
isPointInShape(Point point)
See whether or not a point is inside of a shape.boolean
isPointNearShape(Point point)
See whether or not a point is near (within the hitbox of) a certain circle.boolean
isPointNearShape(Point point, double tolerance)
Get whether or not a given point is within a certain distance of a circle.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
circle
The internal component for the circle. -
hitbox
The internal component for the circle's hitbox. -
center
The center-point of the circle. -
radius
public final double radiusThe radius of the circle itself. -
hitboxRadius
public final double hitboxRadiusThe radius of the circle's hitbox.
-
-
Constructor Details
-
Circle
Create a new circle.- Parameters:
center
- the center-point of the circle.radius
- the radius of the circle. The radius of the circle isn't as important as the hitbox radius, which you'll see in a moment.hitboxRadius
- the radius of the circle's hitbox. Hitboxes, in the context of circles, are what the map sees as a collidable object. By default, the regular circle radius doesn't do much for collisions. However, the hitbox radius does. So cool!
-
-
Method Details
-
isPointInShape
See whether or not a point is inside of a shape.- Specified by:
isPointInShape
in interfaceShape
- Parameters:
point
- the point to check. This could be, for example, one of the end points of a rectangle, a square, the mid-point of a circle, the mid-point (or even quarter-point (or even eighth-point)) of a line.- Returns:
- whether the point is in the circle.
-
isLineInShape
Check whether or not a line enters a shape.TODO implement this method!!!
- Specified by:
isLineInShape
in interfaceShape
- Parameters:
line
- the line to check.- Returns:
- whether or not the line enters the shape.
-
isPointNearShape
See whether or not a point is near (within the hitbox of) a certain circle.- Parameters:
point
- the point to test.- Returns:
- whether or not the point is within the circle's hitbox area.
-
isPointNearShape
Get whether or not a given point is within a certain distance of a circle.- Parameters:
point
- the point to check for.tolerance
- how far away the point can be (max).- Returns:
- whether the point meets our qualifications and wins a grand prize.
-
doesLineIntersectWithCircle
A method to determine whether or not a line intersects with a circle.Just to pre-write some ideas for future use, this could possibly be attempted by doing the following, assuming math is out of the question.
1. Create another (larger) hitbox circle to determine if it's worth even looking for an intersection in the first place. 2. Find the closest point on the line to the radius. If that point is less than or equal to the radius of the circle (not the hitbox), then that line must be touching. 3. Check on the line to make sure the point in question is in fact on the line and not floating off in space. We'll have to see how this plays out, however - oh well.
- Returns:
- whether or not a line intersects with a circle.
-
getComponents
public int getComponents()Get a count of the components in the circle.- Specified by:
getComponents
in interfaceShape
- Returns:
- 4. Because 4.
-