I have the following for a rectangle.. x1,y1,width and height
How can I find x2 and y2 having the values of above?
Draw (x1, y1)
on a piece of paper with a coordinate system and then draw a rectangle of dimensions width x height
on the same paper.
If you make width = 0
, you can say that x1 = x2
. If the widths gets any larger, then x2 > x1
. You can say that x2 = x1 + width
.
The height works the same way, so y2 = y1 + height
.
I assumed that (x1, y1)
is the bottom-left corner's coordinate.
Depending on the point which is represented by x1,y1 and the point you refer to when you say x2,y2 we have the following outputs:-
If x1,y1 is the leftmost-bottom point of the rectangle
then the other 3 points are x1+width,y1
,x1,y1+height
,x1+width,y1+height
If x1,y1 is the rightmost-bottom point of the rectangle
then the other 3 points are x1-width,y1
,x1,y1+height
,x1-width,y1+height
If x1,y1 is the leftmost-top point of the rectangle
then the other 3 points are x1+width,y1
,x1,y1-height
,x1+width,y1-height
If x1,y1 is the rightmost-top point of the rectangle
then the other 3 points are x1-width,y1
,x1,y1-height
,x1-width,y1-height