Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Java Graphics2D coordinate problem

Hi,

I am using Graphics2D to draw graphics for my data for my clustering algorithm result on a JPanel. I understand that Graphics2D start with (0,0) at the top left hand corner to do the painting. However, some of my data on the y axisis -ve value
e.g. (222, -0.002334)

so as it start from (0,0) positve value, it can never paint my data with negative y value.

I try the translate and scale method in grpahics2D, and both can only move the whole thing to other position but actually cannot solve the problem of displaying the negative value.

So my results cant be fully output to the screen.
Is there anyway I can move the (0,0) to the centre and with the ability to output the -ve value?
Does anyone have any ideas on this?

Many thanks

Z

0
zzenith
Asked:
zzenith
1 Solution
 
wide_awakeCommented:
The coordinate plane is fixed, but you can translate everything to the center of the panel yourself.

For example, if you have a method like

drawDataPoint(double xValue, double yValue)
{
  // draw a point at (xValue, yValue)
}

You could change the method to do this:


drawDataPoint(double xValue, double yValue)
{
  // draw a point at ((xValue + getWidth() / 2.0), (yValue + getHeight() / 2.0))
}

That would effectively move your zero-coordinate to the center of the panel.  Of course, you would have to do this for each method that draws things on the panel.  But once you had these methods, you would call drawDataPoint using the original values.

-Mark.
0
 
CleanupPingCommented:
zzenith:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now