Circle2D moment
This commit is contained in:
parent
5fcdbf27fd
commit
d03c3039f7
BIN
C&H pfp.png
Normal file
BIN
C&H pfp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.5 MiB |
@ -109,16 +109,13 @@ public class Circle2D {
|
|||||||
* @param y
|
* @param y
|
||||||
* @return true if the specified point (x, y) is inside the circle, otherwise false.
|
* @return true if the specified point (x, y) is inside the circle, otherwise false.
|
||||||
*/
|
*/
|
||||||
public boolean contains(double x, double y)
|
public boolean contains(Circle2D other)
|
||||||
{
|
{
|
||||||
double d = distance(x, y, this.x, this.y);
|
double dx = this.x - other.x;
|
||||||
return d <= radius;
|
double dy = this.y - other.y;
|
||||||
}
|
double distance = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
public boolean contains(Circle2D c)
|
return distance + other.radius <= this.radius;
|
||||||
{
|
|
||||||
double d = distance(c.x, c.y, this.x, this.y);
|
|
||||||
return d <= radius;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -127,21 +124,13 @@ public class Circle2D {
|
|||||||
* @param circle to compare for overlapping.
|
* @param circle to compare for overlapping.
|
||||||
* @return true
|
* @return true
|
||||||
*/
|
*/
|
||||||
public boolean overlaps(Circle2D c)
|
public boolean overlaps(Circle2D other)
|
||||||
{
|
{
|
||||||
// Compare this to the paremeter
|
double dx = this.x - other.x;
|
||||||
double overlap = Math.sqrt((Math.pow((this.x - c.x), 2) + Math.pow((this.y + c.y), 2)));
|
double dy = this.y - other.y;
|
||||||
|
double distance = Math.sqrt(dx * dx + dy * dy);
|
||||||
if (overlap <= (this.radius - c.radius)) {
|
|
||||||
return true;
|
|
||||||
} else if (overlap <= (c.radius - this.radius)) {
|
|
||||||
return true;
|
|
||||||
} else if (overlap < (this.radius + c.radius)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return distance <= this.radius + other.radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,6 +172,7 @@ public class Circle2D {
|
|||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
Circle2D c1 = new Circle2D(2, 2, 5.5);
|
Circle2D c1 = new Circle2D(2, 2, 5.5);
|
||||||
|
System.out.println(c1);
|
||||||
System.out.println("Area is " + c1.getArea());
|
System.out.println("Area is " + c1.getArea());
|
||||||
System.out.println("Perimeter is " + c1.getPerimeter());
|
System.out.println("Perimeter is " + c1.getPerimeter());
|
||||||
//System.out.println(c1.contains(3, 3));
|
//System.out.println(c1.contains(3, 3));
|
||||||
@ -190,7 +180,18 @@ public class Circle2D {
|
|||||||
//System.out.println(c1.overlaps(new Circle2D(3, 5, 2.3)));
|
//System.out.println(c1.overlaps(new Circle2D(3, 5, 2.3)));
|
||||||
//System.out.println(c1.overlaps(new Circle2D(-8.7, 5, 2.3)));
|
//System.out.println(c1.overlaps(new Circle2D(-8.7, 5, 2.3)));
|
||||||
//System.out.println(c1.overlaps(new Circle2D(-8.7, 5, 2.3)));
|
//System.out.println(c1.overlaps(new Circle2D(-8.7, 5, 2.3)));
|
||||||
System.out.println(c1.contains(new Circle2D(-1.9, 1.8, 2.3)));
|
Circle2D c2 = new Circle2D(-1.9, 1.8, 1.8);
|
||||||
System.out.println(c1.overlaps(new Circle2D(-1.9, 1.8, 2.3)));
|
Circle2D c3 = new Circle2D(-1.9, 1.8, 0.8);
|
||||||
|
Circle2D c4 = new Circle2D(-6.2, 1.8, 1.8);
|
||||||
|
System.out.println(c2);
|
||||||
|
System.out.println("c1.contains: " + c1.contains(c2));
|
||||||
|
System.out.println("c1.overlaps: " + c1.overlaps(c2));
|
||||||
|
System.out.println(c3);
|
||||||
|
System.out.println("c1.contains: " + c1.contains(c3));
|
||||||
|
System.out.println("c1.overlaps: " + c1.overlaps(c3));
|
||||||
|
System.out.println(c4);
|
||||||
|
System.out.println("c1.contains: " + c1.contains(c4));
|
||||||
|
System.out.println("c1.overlaps: " + c1.overlaps(c4));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
gource_ASDV-Java.mp4
Normal file
BIN
gource_ASDV-Java.mp4
Normal file
Binary file not shown.
BIN
gource_ASDV-Java2.mp4
Normal file
BIN
gource_ASDV-Java2.mp4
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user