Java coordinate systems
hi! i am having a problem of figuring on how device coordinate system used by awt be converted to rectangular coordinates. Do you have any ideas? Thanks
[166 byte] By [
chiwena] at [2007-11-26 17:02:26]

sorry.. here are the details.
I have a JPanel where the user draw points, just like a painter. I capture these points in pixels using mouse events. I want to convert this points(in pixels) into points in rectangular coordinate system where decimals are allowed.
i need those converted points to compute for an interpolation. Are all details above alright? thanks!!
I think the origin of the AWT coordinate system is in the upper left corner of the screen. The extent of the (x, y) window depends on the resolution of your monitor (1024 x 768, etc.)%
how can i convert those pixels into coordinates?
Just like any other affine transformation, right? You need a mapping.%
> how can i convert those pixels into coordinates?You could make your own method to convert it, but I would recommend just getting used to it.
but rectangular coordinates do have decimals numbers while pixels do not have. so I really need to convert it.. huhu
> but rectangular coordinates do have decimals numbers> while pixels do not have.What's your point? Do you want to draw a line that is 2.75 pixels long?
you got it sir.. do you have any ideas?
> but rectangular coordinates do have decimals numbers> while pixels do not have. so I really need to convert> it.. huhutruncate.%
or round. whatever is acceptable to you.%
> you got it sir.. do you have any ideas?Yes I do. Suck it up and use the AWT coordinate system.
i cant round off, its decimals are very important.. it may distort what am i drawing because my goal is to smooth a curve through interpolation.. e.g. the user draws a curve a straight, i must smooth it to eliminate noise.. ty!
> i cant round off, its decimals are very important..You can't draw part of a pixel.
yep yep, that's another reason why should i convert it.
> yep yep, that's another reason why should i convert> it.You aren't making any sense. Each coordinate represents one pixel on the screen. Why do you need more precision than that?
> i cant round off, its decimals are very important..
> it may distort what am i drawing because my goal is
> to smooth a curve through interpolation..
> e.g. the user draws a curve a straight, i must smooth
> it to eliminate noise.. ty!
If you draw a straight line at a 45 degree angle along the screen, you're going to get a staircase effect no matter what you do, because that's the best a pixel screen can do.
Seems awfully low level. Ever thought about Java2D or a graphics package that would handle this drawing for you? They probably do a better job of it than you will.
%
You are asking for a method to convert a less precise system to a more precise system but thing can only be done the other way round.