Results 1 to 4 of 4
- 02-07-2010, 11:44 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 5
- Rep Power
- 0
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()
-
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.
- 02-07-2010, 09:27 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 5
- Rep Power
- 0
ye this seems to work:
for x:
Java Code:int newX = (int) ( (x + 1) * width/2 )
Java Code:int newY = (int) ( (y - 1) * -height/2 )
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 09:32 PM.
-
If you want to always stretch the graph to fit the view I'd change this:
Java Code:int newY = (int) ( (y - 1) * -width/2 )
Java Code:int newY = (int) ( (y - 1) * -height/2 )
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.
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.
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?
Similar Threads
-
Ovals with the same X coordinate and different radiuses
By veseo in forum Java 2DReplies: 3Last Post: 12-15-2009, 10:20 PM -
[SOLVED] how to put string to JLabel with coordinate
By tOpach in forum New To JavaReplies: 4Last Post: 12-17-2008, 06:57 PM -
How to show pixel Coordinate and RGB value when mouse is tracking over an image
By Mazharul in forum Java 2DReplies: 1Last Post: 08-25-2008, 09:48 PM -
set coordinate to an image
By nuur in forum AWT / SwingReplies: 2Last Post: 04-01-2008, 09:08 AM -
X&Y Coordinate Drawing on jPanel
By BHCluster in forum Java 2DReplies: 2Last Post: 03-27-2008, 11:47 AM
Bookmarks