The Artima Developer Community
Sponsored Link

Java Answers Forum
Drawing negative rectangles?

3 replies on 1 page. Most recent reply: Feb 5, 2003 1:31 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Max Lyn

Posts: 11
Nickname: techrolla
Registered: Feb, 2003

Drawing negative rectangles? Posted: Feb 2, 2003 10:40 PM
Reply to this message Reply
Advertisement
How do you draw a rectangle that would have negative values for height a width?? Like on a drawing program, being able to draw rectangle around all axes when the mouse moves, instead of just a right-down drag rectangle. Please help!


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Drawing negative rectangles? Posted: Feb 3, 2003 5:48 PM
Reply to this message Reply
You just offset your coordinate system, so that (0,0) is in the middle of the frame.

Max Lyn

Posts: 11
Nickname: techrolla
Registered: Feb, 2003

Re: Drawing negative rectangles? Posted: Feb 4, 2003 9:27 PM
Reply to this message Reply
how would this be done?

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: Drawing negative rectangles? Posted: Feb 5, 2003 1:31 PM
Reply to this message Reply
Well, I'd create a little CoordinateTransmogrifier class to convert between the coordinate system of your domain and the coordinates of the frame where you are drawing. This class would be initialized with the bounds of both coordinate sytems, then it could convert both ways with ease. It may seem like overkill, but it would make changing the mappings simpler.

For example, lets say you can draw points ranging from -100 to +100 in both dimensions (x and y) and your frame is 200 x 200 pixels (how convenient!). Then, whenever you want to draw a point from your function y = f(x), you just add 100 to the x value and 100 to the calculated y value, then draw that point.

Flat View: This topic has 3 replies on 1 page
Topic: mapping a int Previous Topic   Next Topic Topic: Determine if input number  is  prime

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use