Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2010, 10:44 AM
123 123 is offline
Member
 
Join Date: Feb 2010
Posts: 5
Rep Power: 0
123 is on a distinguished road
Default Convert Cartesian coordinate system into java coordinate system?
Please give me a way to code a method to convert cartesian coord. into java/picture coord. system I'm not supposed to use predefined functions like affine, scale(), transform, etc for this method.

Heres the picture:

For eg. i want to plot a point on java system from cartesian coordinates: (0.905, 0.360) & (-0.023, 0.410)
I need write the code inside the method: coordinateToPixel()
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-07-2010, 02:13 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 8,431
Rep Power: 11
Fubarable is on a distinguished road
Default
Surely you've tried something yourself first as it's simple algebra. Why not show us this code and describe what problems you are having with it.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-07-2010, 08:27 PM
123 123 is offline
Member
 
Join Date: Feb 2010
Posts: 5
Rep Power: 0
123 is on a distinguished road
Default
ye this seems to work:
for x:
Code:
int newX = (int) ( (x + 1) * width/2 )
for y:
Code:
int newY = (int) ( (y - 1) * -height/2 )
where, width & height = 1000 pixels (in this case)

Please tell if casting this into a int is required. I thought Java coord. system only takes int values. My x & y are all double value and are stored in an object array.

Now i want to assign newX & newY into the original x & y values.
And also use newX & newY to draw shapes into system.
How to do this?

Last edited by 123; 02-07-2010 at 08:32 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-07-2010, 08:34 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 8,431
Rep Power: 11
Fubarable is on a distinguished road
Default
If you want to always stretch the graph to fit the view I'd change this:
Code:
int newY = (int) ( (y - 1) * -width/2 )
to this:
Code:
int newY = (int) ( (y - 1) * -height/2 )
your height may == width now, but this may not always be the case.

If on the other hand you want to always maintain a square symmetry, then you could always check which is greater height or width and use the lesser of the two as your scaling factor.

Quote:
Please tell if casting this into a int is required. I thought Java coord. system only takes int values. My x & y are all double value type.
The methods you use should tell you when int is required. For instance many Shape object derived methods and constructors will happily use floating point variables, for instance the methods of Point2D, while most (all?) of the Graphics draw methods require ints. Here's where the Java API becomes indispensable.

Quote:
Now i want to assign newX & newY into the original x & y values.
And also use newX & newY to draw shapes into system.
How to do this?
I'm not sure what you're asking here. More details may help.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ovals with the same X coordinate and different radiuses veseo Java 2D 3 12-15-2009 09:20 PM
[SOLVED] how to put string to JLabel with coordinate tOpach New To Java 4 12-17-2008 05:57 PM
How to show pixel Coordinate and RGB value when mouse is tracking over an image Mazharul Java 2D 1 08-25-2008 08:48 PM
set coordinate to an image nuur AWT / Swing 2 04-01-2008 08:08 AM
X&Y Coordinate Drawing on jPanel BHCluster Java 2D 2 03-27-2008 10:47 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:59 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org