Geometry, Two Rectangles Overlapping, Sharing Boundaries, Distinct
up vote
2
down vote
favorite
So I have this program that needs to test two rectangles and check:
- If the test rectangle is within the reference rectangle
- If the test rectangle is overlapping the reference rectangle
- If the test rectangle is only sharing a border with the reference rectangle
- If the test rectangle and reference rectangle are distinct
Both the reference and test rectangles are defined with their center coordinates (x,y) and their width and height.
I believe I have the first check coded correctly, but I cannot figure out the math for the last three checks of overlapping, sharing boundary, and being totally distinct.
I understand this isn't a programming site but my issue is purely math related not programming related. Whenever it says this.variable it is referring to the reference rectangle's value. r.variable is referring to the rectangle being tested against the reference rectangle.
Here is my code for the four checks so far:
//returns true if the specified rectangle is inside this rectangle
public boolean contains(MyRectangle2D r){
if(this.x > r.x + r.width && x + width < r.x && y > r.y +r.height && y + height < r.y){
return true;
}
else{
return false;
}
}
//returns true if the specified rectangle overlaps with this rectangle
public boolean overlaps(MyRectangle2D r) {
if (this.x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y){
return true;
}
else{
return false;
}
}
//returns true if only the boundaries touch
public boolean abut(MyRectangle2D r) {
if(this.x = r.x + r.width && x + width = r.x || y = r.y +r.height && y + height = r.y){
return true;
}
else{
return false;
}
}
//returns true if the rectangles are not touching at all
public boolean distinct(MyRectangle2D r) {
}
Any help is greatly appreciated, thank you!
geometry
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
|
show 1 more comment
up vote
2
down vote
favorite
So I have this program that needs to test two rectangles and check:
- If the test rectangle is within the reference rectangle
- If the test rectangle is overlapping the reference rectangle
- If the test rectangle is only sharing a border with the reference rectangle
- If the test rectangle and reference rectangle are distinct
Both the reference and test rectangles are defined with their center coordinates (x,y) and their width and height.
I believe I have the first check coded correctly, but I cannot figure out the math for the last three checks of overlapping, sharing boundary, and being totally distinct.
I understand this isn't a programming site but my issue is purely math related not programming related. Whenever it says this.variable it is referring to the reference rectangle's value. r.variable is referring to the rectangle being tested against the reference rectangle.
Here is my code for the four checks so far:
//returns true if the specified rectangle is inside this rectangle
public boolean contains(MyRectangle2D r){
if(this.x > r.x + r.width && x + width < r.x && y > r.y +r.height && y + height < r.y){
return true;
}
else{
return false;
}
}
//returns true if the specified rectangle overlaps with this rectangle
public boolean overlaps(MyRectangle2D r) {
if (this.x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y){
return true;
}
else{
return false;
}
}
//returns true if only the boundaries touch
public boolean abut(MyRectangle2D r) {
if(this.x = r.x + r.width && x + width = r.x || y = r.y +r.height && y + height = r.y){
return true;
}
else{
return false;
}
}
//returns true if the rectangles are not touching at all
public boolean distinct(MyRectangle2D r) {
}
Any help is greatly appreciated, thank you!
geometry
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
Was this assigned to you from school? Unless it was, I would personally define a rectangle by a lower left and a upper right coordinate (notice this creates a rectangle) mainly because it is much easier to if there is an intersection using the x and y values.
– Ian Limarta
Aug 6 '16 at 4:20
@EugenCovaci AFAIK, the Java language doesn’t treat rectangles at all. For the Java awt Rectangle class, its coordinates are those of the top left corner. In the code included in this question, the rectangles are of classMyRectangle2D
, which looks pretty nonstandard to me.
– amd
Aug 6 '16 at 7:22
@amd By Java language I mean everything Java SDK has to offer. AWT is part of Java standard and the class java.awt.geom.Rectangle2D is abstract, ready to be extended, witch I suppose the OP did. Also JavaFX has javafx.geometry.Rectangle2D a concrete class having some methods like "boolean contains(Point2D p), boolean intersects(double x, double y, double w, double h) " that OP might be interested with. Both classes are part of Java Standard and both treat rectangles the way OD did. BTW, I'm Java certified programmer since 2007.
– user261263
Aug 6 '16 at 7:41
@EugenCovaci Are you sure about that? Take, for example docs.oracle.com/javase/8/javafx/api/javafx/geometry/…, which describes the rectangle’s location (as used in the constructor) as “minX, minY.” That doesn’t sound like its center to me, nor do any of the methods documented there return a center point.
– amd
Aug 6 '16 at 7:52
1
A detail: It is implicit, but it should be said explicitly in your question that all rectangles have their sides parallel to one of the coordinate's axes.
– Jean Marie
Aug 6 '16 at 10:52
|
show 1 more comment
up vote
2
down vote
favorite
up vote
2
down vote
favorite
So I have this program that needs to test two rectangles and check:
- If the test rectangle is within the reference rectangle
- If the test rectangle is overlapping the reference rectangle
- If the test rectangle is only sharing a border with the reference rectangle
- If the test rectangle and reference rectangle are distinct
Both the reference and test rectangles are defined with their center coordinates (x,y) and their width and height.
I believe I have the first check coded correctly, but I cannot figure out the math for the last three checks of overlapping, sharing boundary, and being totally distinct.
I understand this isn't a programming site but my issue is purely math related not programming related. Whenever it says this.variable it is referring to the reference rectangle's value. r.variable is referring to the rectangle being tested against the reference rectangle.
Here is my code for the four checks so far:
//returns true if the specified rectangle is inside this rectangle
public boolean contains(MyRectangle2D r){
if(this.x > r.x + r.width && x + width < r.x && y > r.y +r.height && y + height < r.y){
return true;
}
else{
return false;
}
}
//returns true if the specified rectangle overlaps with this rectangle
public boolean overlaps(MyRectangle2D r) {
if (this.x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y){
return true;
}
else{
return false;
}
}
//returns true if only the boundaries touch
public boolean abut(MyRectangle2D r) {
if(this.x = r.x + r.width && x + width = r.x || y = r.y +r.height && y + height = r.y){
return true;
}
else{
return false;
}
}
//returns true if the rectangles are not touching at all
public boolean distinct(MyRectangle2D r) {
}
Any help is greatly appreciated, thank you!
geometry
So I have this program that needs to test two rectangles and check:
- If the test rectangle is within the reference rectangle
- If the test rectangle is overlapping the reference rectangle
- If the test rectangle is only sharing a border with the reference rectangle
- If the test rectangle and reference rectangle are distinct
Both the reference and test rectangles are defined with their center coordinates (x,y) and their width and height.
I believe I have the first check coded correctly, but I cannot figure out the math for the last three checks of overlapping, sharing boundary, and being totally distinct.
I understand this isn't a programming site but my issue is purely math related not programming related. Whenever it says this.variable it is referring to the reference rectangle's value. r.variable is referring to the rectangle being tested against the reference rectangle.
Here is my code for the four checks so far:
//returns true if the specified rectangle is inside this rectangle
public boolean contains(MyRectangle2D r){
if(this.x > r.x + r.width && x + width < r.x && y > r.y +r.height && y + height < r.y){
return true;
}
else{
return false;
}
}
//returns true if the specified rectangle overlaps with this rectangle
public boolean overlaps(MyRectangle2D r) {
if (this.x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y){
return true;
}
else{
return false;
}
}
//returns true if only the boundaries touch
public boolean abut(MyRectangle2D r) {
if(this.x = r.x + r.width && x + width = r.x || y = r.y +r.height && y + height = r.y){
return true;
}
else{
return false;
}
}
//returns true if the rectangles are not touching at all
public boolean distinct(MyRectangle2D r) {
}
Any help is greatly appreciated, thank you!
geometry
geometry
edited Aug 6 '16 at 4:12
MathTrain
659215
659215
asked Aug 6 '16 at 4:01
user359637
112
112
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
1
Was this assigned to you from school? Unless it was, I would personally define a rectangle by a lower left and a upper right coordinate (notice this creates a rectangle) mainly because it is much easier to if there is an intersection using the x and y values.
– Ian Limarta
Aug 6 '16 at 4:20
@EugenCovaci AFAIK, the Java language doesn’t treat rectangles at all. For the Java awt Rectangle class, its coordinates are those of the top left corner. In the code included in this question, the rectangles are of classMyRectangle2D
, which looks pretty nonstandard to me.
– amd
Aug 6 '16 at 7:22
@amd By Java language I mean everything Java SDK has to offer. AWT is part of Java standard and the class java.awt.geom.Rectangle2D is abstract, ready to be extended, witch I suppose the OP did. Also JavaFX has javafx.geometry.Rectangle2D a concrete class having some methods like "boolean contains(Point2D p), boolean intersects(double x, double y, double w, double h) " that OP might be interested with. Both classes are part of Java Standard and both treat rectangles the way OD did. BTW, I'm Java certified programmer since 2007.
– user261263
Aug 6 '16 at 7:41
@EugenCovaci Are you sure about that? Take, for example docs.oracle.com/javase/8/javafx/api/javafx/geometry/…, which describes the rectangle’s location (as used in the constructor) as “minX, minY.” That doesn’t sound like its center to me, nor do any of the methods documented there return a center point.
– amd
Aug 6 '16 at 7:52
1
A detail: It is implicit, but it should be said explicitly in your question that all rectangles have their sides parallel to one of the coordinate's axes.
– Jean Marie
Aug 6 '16 at 10:52
|
show 1 more comment
1
Was this assigned to you from school? Unless it was, I would personally define a rectangle by a lower left and a upper right coordinate (notice this creates a rectangle) mainly because it is much easier to if there is an intersection using the x and y values.
– Ian Limarta
Aug 6 '16 at 4:20
@EugenCovaci AFAIK, the Java language doesn’t treat rectangles at all. For the Java awt Rectangle class, its coordinates are those of the top left corner. In the code included in this question, the rectangles are of classMyRectangle2D
, which looks pretty nonstandard to me.
– amd
Aug 6 '16 at 7:22
@amd By Java language I mean everything Java SDK has to offer. AWT is part of Java standard and the class java.awt.geom.Rectangle2D is abstract, ready to be extended, witch I suppose the OP did. Also JavaFX has javafx.geometry.Rectangle2D a concrete class having some methods like "boolean contains(Point2D p), boolean intersects(double x, double y, double w, double h) " that OP might be interested with. Both classes are part of Java Standard and both treat rectangles the way OD did. BTW, I'm Java certified programmer since 2007.
– user261263
Aug 6 '16 at 7:41
@EugenCovaci Are you sure about that? Take, for example docs.oracle.com/javase/8/javafx/api/javafx/geometry/…, which describes the rectangle’s location (as used in the constructor) as “minX, minY.” That doesn’t sound like its center to me, nor do any of the methods documented there return a center point.
– amd
Aug 6 '16 at 7:52
1
A detail: It is implicit, but it should be said explicitly in your question that all rectangles have their sides parallel to one of the coordinate's axes.
– Jean Marie
Aug 6 '16 at 10:52
1
1
Was this assigned to you from school? Unless it was, I would personally define a rectangle by a lower left and a upper right coordinate (notice this creates a rectangle) mainly because it is much easier to if there is an intersection using the x and y values.
– Ian Limarta
Aug 6 '16 at 4:20
Was this assigned to you from school? Unless it was, I would personally define a rectangle by a lower left and a upper right coordinate (notice this creates a rectangle) mainly because it is much easier to if there is an intersection using the x and y values.
– Ian Limarta
Aug 6 '16 at 4:20
@EugenCovaci AFAIK, the Java language doesn’t treat rectangles at all. For the Java awt Rectangle class, its coordinates are those of the top left corner. In the code included in this question, the rectangles are of class
MyRectangle2D
, which looks pretty nonstandard to me.– amd
Aug 6 '16 at 7:22
@EugenCovaci AFAIK, the Java language doesn’t treat rectangles at all. For the Java awt Rectangle class, its coordinates are those of the top left corner. In the code included in this question, the rectangles are of class
MyRectangle2D
, which looks pretty nonstandard to me.– amd
Aug 6 '16 at 7:22
@amd By Java language I mean everything Java SDK has to offer. AWT is part of Java standard and the class java.awt.geom.Rectangle2D is abstract, ready to be extended, witch I suppose the OP did. Also JavaFX has javafx.geometry.Rectangle2D a concrete class having some methods like "boolean contains(Point2D p), boolean intersects(double x, double y, double w, double h) " that OP might be interested with. Both classes are part of Java Standard and both treat rectangles the way OD did. BTW, I'm Java certified programmer since 2007.
– user261263
Aug 6 '16 at 7:41
@amd By Java language I mean everything Java SDK has to offer. AWT is part of Java standard and the class java.awt.geom.Rectangle2D is abstract, ready to be extended, witch I suppose the OP did. Also JavaFX has javafx.geometry.Rectangle2D a concrete class having some methods like "boolean contains(Point2D p), boolean intersects(double x, double y, double w, double h) " that OP might be interested with. Both classes are part of Java Standard and both treat rectangles the way OD did. BTW, I'm Java certified programmer since 2007.
– user261263
Aug 6 '16 at 7:41
@EugenCovaci Are you sure about that? Take, for example docs.oracle.com/javase/8/javafx/api/javafx/geometry/…, which describes the rectangle’s location (as used in the constructor) as “minX, minY.” That doesn’t sound like its center to me, nor do any of the methods documented there return a center point.
– amd
Aug 6 '16 at 7:52
@EugenCovaci Are you sure about that? Take, for example docs.oracle.com/javase/8/javafx/api/javafx/geometry/…, which describes the rectangle’s location (as used in the constructor) as “minX, minY.” That doesn’t sound like its center to me, nor do any of the methods documented there return a center point.
– amd
Aug 6 '16 at 7:52
1
1
A detail: It is implicit, but it should be said explicitly in your question that all rectangles have their sides parallel to one of the coordinate's axes.
– Jean Marie
Aug 6 '16 at 10:52
A detail: It is implicit, but it should be said explicitly in your question that all rectangles have their sides parallel to one of the coordinate's axes.
– Jean Marie
Aug 6 '16 at 10:52
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
0
down vote
I'm not going to write all the code, but mathematically I'll try to give an idea of what to check for.
First I'll define "reach" as half the width (for the x direction) or half the height (for the y). I call it reach because that's how far the rectangle can "reach" from its center (x,y) to other parts of the plane.
In order to check if they overlap, first check if the sum of their "reaches" (half their widths/heights) in the x direction is greater than the x-distance between them. Then do the same for the y direction and y "reach". I'm not going to write the code, but roughly:
if(w1/2+w2/2>abs(x1-x2)){
if(h1/2+h2/2>abs(y1-y2)){
return true.
if the reaches aren't more than the distances, they don't overlap.
If they only share a border, then one of four things could be true:
- The x coordinate of the first rectangle plus its reach is equal to the x coordinate of the second one minus its reach (x1+w1/2=x2-w2/2).
- The x coordinate of the second rectangle plus its reach is equal to the x coordinate of the first one minus its reach (x2+w2/2=x1-w1/2).
- The next two are the same except replace all x's with y's and all w's with h's.
The rectangles can only be totally distinct if there is no border touching and no overlap, so if all of the others return false then they must be totally distinct.
add a comment |
up vote
0
down vote
First of all, distinct = not contains and not overlap and not boundaries touch.
I would start by writing two method in MyRectangle2D class like this:
boolean isPointInside(int x, int y)
boolean isPointOnBoundary(int x, int y)
to check when the point (x, y) is inside the current rectangle or on the boundary.
Then:
public boolean contains(MyRectangle2D r){
//all r tips are inside the current rectangle.
//Use isPointInside function
}
public boolean overlaps(MyRectangle2D r) {
//one and only one of r tips is inside the current rectangle.
//Use isPointInside function and contains function to check it is not contained
}
public boolean abut(MyRectangle2D r) {
//at least one of r corners is on the current rectangle boundary.
//Use isPointOnBoundary function
}
public boolean distinct(MyRectangle2D r) {
return ! contains(r) && ! overlaps(r) & ! abut(r);
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I'm not going to write all the code, but mathematically I'll try to give an idea of what to check for.
First I'll define "reach" as half the width (for the x direction) or half the height (for the y). I call it reach because that's how far the rectangle can "reach" from its center (x,y) to other parts of the plane.
In order to check if they overlap, first check if the sum of their "reaches" (half their widths/heights) in the x direction is greater than the x-distance between them. Then do the same for the y direction and y "reach". I'm not going to write the code, but roughly:
if(w1/2+w2/2>abs(x1-x2)){
if(h1/2+h2/2>abs(y1-y2)){
return true.
if the reaches aren't more than the distances, they don't overlap.
If they only share a border, then one of four things could be true:
- The x coordinate of the first rectangle plus its reach is equal to the x coordinate of the second one minus its reach (x1+w1/2=x2-w2/2).
- The x coordinate of the second rectangle plus its reach is equal to the x coordinate of the first one minus its reach (x2+w2/2=x1-w1/2).
- The next two are the same except replace all x's with y's and all w's with h's.
The rectangles can only be totally distinct if there is no border touching and no overlap, so if all of the others return false then they must be totally distinct.
add a comment |
up vote
0
down vote
I'm not going to write all the code, but mathematically I'll try to give an idea of what to check for.
First I'll define "reach" as half the width (for the x direction) or half the height (for the y). I call it reach because that's how far the rectangle can "reach" from its center (x,y) to other parts of the plane.
In order to check if they overlap, first check if the sum of their "reaches" (half their widths/heights) in the x direction is greater than the x-distance between them. Then do the same for the y direction and y "reach". I'm not going to write the code, but roughly:
if(w1/2+w2/2>abs(x1-x2)){
if(h1/2+h2/2>abs(y1-y2)){
return true.
if the reaches aren't more than the distances, they don't overlap.
If they only share a border, then one of four things could be true:
- The x coordinate of the first rectangle plus its reach is equal to the x coordinate of the second one minus its reach (x1+w1/2=x2-w2/2).
- The x coordinate of the second rectangle plus its reach is equal to the x coordinate of the first one minus its reach (x2+w2/2=x1-w1/2).
- The next two are the same except replace all x's with y's and all w's with h's.
The rectangles can only be totally distinct if there is no border touching and no overlap, so if all of the others return false then they must be totally distinct.
add a comment |
up vote
0
down vote
up vote
0
down vote
I'm not going to write all the code, but mathematically I'll try to give an idea of what to check for.
First I'll define "reach" as half the width (for the x direction) or half the height (for the y). I call it reach because that's how far the rectangle can "reach" from its center (x,y) to other parts of the plane.
In order to check if they overlap, first check if the sum of their "reaches" (half their widths/heights) in the x direction is greater than the x-distance between them. Then do the same for the y direction and y "reach". I'm not going to write the code, but roughly:
if(w1/2+w2/2>abs(x1-x2)){
if(h1/2+h2/2>abs(y1-y2)){
return true.
if the reaches aren't more than the distances, they don't overlap.
If they only share a border, then one of four things could be true:
- The x coordinate of the first rectangle plus its reach is equal to the x coordinate of the second one minus its reach (x1+w1/2=x2-w2/2).
- The x coordinate of the second rectangle plus its reach is equal to the x coordinate of the first one minus its reach (x2+w2/2=x1-w1/2).
- The next two are the same except replace all x's with y's and all w's with h's.
The rectangles can only be totally distinct if there is no border touching and no overlap, so if all of the others return false then they must be totally distinct.
I'm not going to write all the code, but mathematically I'll try to give an idea of what to check for.
First I'll define "reach" as half the width (for the x direction) or half the height (for the y). I call it reach because that's how far the rectangle can "reach" from its center (x,y) to other parts of the plane.
In order to check if they overlap, first check if the sum of their "reaches" (half their widths/heights) in the x direction is greater than the x-distance between them. Then do the same for the y direction and y "reach". I'm not going to write the code, but roughly:
if(w1/2+w2/2>abs(x1-x2)){
if(h1/2+h2/2>abs(y1-y2)){
return true.
if the reaches aren't more than the distances, they don't overlap.
If they only share a border, then one of four things could be true:
- The x coordinate of the first rectangle plus its reach is equal to the x coordinate of the second one minus its reach (x1+w1/2=x2-w2/2).
- The x coordinate of the second rectangle plus its reach is equal to the x coordinate of the first one minus its reach (x2+w2/2=x1-w1/2).
- The next two are the same except replace all x's with y's and all w's with h's.
The rectangles can only be totally distinct if there is no border touching and no overlap, so if all of the others return false then they must be totally distinct.
answered Aug 6 '16 at 4:29
MathTrain
659215
659215
add a comment |
add a comment |
up vote
0
down vote
First of all, distinct = not contains and not overlap and not boundaries touch.
I would start by writing two method in MyRectangle2D class like this:
boolean isPointInside(int x, int y)
boolean isPointOnBoundary(int x, int y)
to check when the point (x, y) is inside the current rectangle or on the boundary.
Then:
public boolean contains(MyRectangle2D r){
//all r tips are inside the current rectangle.
//Use isPointInside function
}
public boolean overlaps(MyRectangle2D r) {
//one and only one of r tips is inside the current rectangle.
//Use isPointInside function and contains function to check it is not contained
}
public boolean abut(MyRectangle2D r) {
//at least one of r corners is on the current rectangle boundary.
//Use isPointOnBoundary function
}
public boolean distinct(MyRectangle2D r) {
return ! contains(r) && ! overlaps(r) & ! abut(r);
}
add a comment |
up vote
0
down vote
First of all, distinct = not contains and not overlap and not boundaries touch.
I would start by writing two method in MyRectangle2D class like this:
boolean isPointInside(int x, int y)
boolean isPointOnBoundary(int x, int y)
to check when the point (x, y) is inside the current rectangle or on the boundary.
Then:
public boolean contains(MyRectangle2D r){
//all r tips are inside the current rectangle.
//Use isPointInside function
}
public boolean overlaps(MyRectangle2D r) {
//one and only one of r tips is inside the current rectangle.
//Use isPointInside function and contains function to check it is not contained
}
public boolean abut(MyRectangle2D r) {
//at least one of r corners is on the current rectangle boundary.
//Use isPointOnBoundary function
}
public boolean distinct(MyRectangle2D r) {
return ! contains(r) && ! overlaps(r) & ! abut(r);
}
add a comment |
up vote
0
down vote
up vote
0
down vote
First of all, distinct = not contains and not overlap and not boundaries touch.
I would start by writing two method in MyRectangle2D class like this:
boolean isPointInside(int x, int y)
boolean isPointOnBoundary(int x, int y)
to check when the point (x, y) is inside the current rectangle or on the boundary.
Then:
public boolean contains(MyRectangle2D r){
//all r tips are inside the current rectangle.
//Use isPointInside function
}
public boolean overlaps(MyRectangle2D r) {
//one and only one of r tips is inside the current rectangle.
//Use isPointInside function and contains function to check it is not contained
}
public boolean abut(MyRectangle2D r) {
//at least one of r corners is on the current rectangle boundary.
//Use isPointOnBoundary function
}
public boolean distinct(MyRectangle2D r) {
return ! contains(r) && ! overlaps(r) & ! abut(r);
}
First of all, distinct = not contains and not overlap and not boundaries touch.
I would start by writing two method in MyRectangle2D class like this:
boolean isPointInside(int x, int y)
boolean isPointOnBoundary(int x, int y)
to check when the point (x, y) is inside the current rectangle or on the boundary.
Then:
public boolean contains(MyRectangle2D r){
//all r tips are inside the current rectangle.
//Use isPointInside function
}
public boolean overlaps(MyRectangle2D r) {
//one and only one of r tips is inside the current rectangle.
//Use isPointInside function and contains function to check it is not contained
}
public boolean abut(MyRectangle2D r) {
//at least one of r corners is on the current rectangle boundary.
//Use isPointOnBoundary function
}
public boolean distinct(MyRectangle2D r) {
return ! contains(r) && ! overlaps(r) & ! abut(r);
}
answered Aug 6 '16 at 4:46
user261263
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1883959%2fgeometry-two-rectangles-overlapping-sharing-boundaries-distinct%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Was this assigned to you from school? Unless it was, I would personally define a rectangle by a lower left and a upper right coordinate (notice this creates a rectangle) mainly because it is much easier to if there is an intersection using the x and y values.
– Ian Limarta
Aug 6 '16 at 4:20
@EugenCovaci AFAIK, the Java language doesn’t treat rectangles at all. For the Java awt Rectangle class, its coordinates are those of the top left corner. In the code included in this question, the rectangles are of class
MyRectangle2D
, which looks pretty nonstandard to me.– amd
Aug 6 '16 at 7:22
@amd By Java language I mean everything Java SDK has to offer. AWT is part of Java standard and the class java.awt.geom.Rectangle2D is abstract, ready to be extended, witch I suppose the OP did. Also JavaFX has javafx.geometry.Rectangle2D a concrete class having some methods like "boolean contains(Point2D p), boolean intersects(double x, double y, double w, double h) " that OP might be interested with. Both classes are part of Java Standard and both treat rectangles the way OD did. BTW, I'm Java certified programmer since 2007.
– user261263
Aug 6 '16 at 7:41
@EugenCovaci Are you sure about that? Take, for example docs.oracle.com/javase/8/javafx/api/javafx/geometry/…, which describes the rectangle’s location (as used in the constructor) as “minX, minY.” That doesn’t sound like its center to me, nor do any of the methods documented there return a center point.
– amd
Aug 6 '16 at 7:52
1
A detail: It is implicit, but it should be said explicitly in your question that all rectangles have their sides parallel to one of the coordinate's axes.
– Jean Marie
Aug 6 '16 at 10:52