math ppl HELP. drawing shapes in java

Status
Not open for further replies.

ibexpiotr

In Runtime
Messages
243
Location
New York
ok so heres the deal..
i've got few methods, for drawing shapes(squares circles...)
i have 2 points.. each has x and y coordinates.

the drawing methods look like this
ex: drawRect(int x, int y, int width, int height)

ive come up with the algorithms for drawing a rectangle by dragging mouse from the top left corner to the bottom right.

and also from bottom right to top left.

what would the algorithms be for drawing them from top right to bottom left, and from bottom left to top right
 
Drawing rectangles and circles is all based on the top-left corner of the rectangle that holds your shape, so you have to know the top-left corner points. if I was dragging from top-right to bottom-left what I would do would be first check which way you were dragging by checking if your x1 was bigger or smaller than x2, and if your y1 was bigger or smaller than y2(top-left: x2>x1 y2>y1, top-right: x2<x1 y2>y1) then I would use those points in a certain way according to the way you were dragging to figure out what the top-left coord is. So if you drug from a top-right coord of 10,10 to a bottom-left coord of 0,20 your top left coord would be 0,10 and your size would be 10x10. Hope that helps.
 
Status
Not open for further replies.
Back
Top Bottom