?
Solved

Java Graphics2D  coordinate problem

Posted on 2003-03-21
3
Medium Priority
?
343 Views
Last Modified: 2011-10-03
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
Comment
Question by:zzenith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
wide_awake earned 300 total points
ID: 8187117
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
 

Expert Comment

by:CleanupPing
ID: 9446906
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month8 days, 12 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question