Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » math ppl HELP. drawing shapes in java
Closed Thread
Old 12-09-2005, 01:31 PM   #1 (permalink)
ibexpiotr's Avatar
 
True Techie

Join Date: Nov 2003

Posts: 197

ibexpiotr is on a distinguished road

Send a message via AIM to ibexpiotr
Default math ppl HELP. drawing shapes in java

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
ibexpiotr is offline  
Old 12-13-2005, 09:44 PM   #2 (permalink)
 
Newb Techie

Join Date: Oct 2004

Posts: 20

MrMarcDee

Default

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.
MrMarcDee is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On