Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Getting new coordinates

Reply
Thread Tools

Getting new coordinates

 
 
Chantal
Guest
Posts: n/a
 
      01-24-2006
Hello,

I'm translating and rotating a polygon with graphics2D (g2) and
everything works fine :

g2.translate(x, y);
g2.rotate(r);
g2.drawPolygon(pol);
//reinit
g2.translate(-x, -y);
g2.rotate(-r);

But I would like to know if it's possible to get the new coordinates of
the polygon, I mean after the rotation and translation are done.

To be complete, I'm doing a translation and a rotation on a image too.
So i draw first my image and after I draw my polygon.
So my image and polygon perfectly match but I need to get the new
coordinates of my polygon.

I tried to rotate and translate my polygon with maths without using
dedicated graphics2D functions (the image is still translated and
rotated with graphics2D) but the figures don't match anymore (several
pixels of difference).

So, if there was a possibility to get the new coordinates of my polygon
with the first solution (everything done with graphics2D), it would be
great !!

Thanks in advance, )

Chantal

 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      01-24-2006
Chantal wrote:
> I'm translating and rotating a polygon with graphics2D (g2) and
> everything works fine :
>
> g2.translate(x, y);
> g2.rotate(r);
> g2.drawPolygon(pol);
> //reinit


It is better to keep a copy of the original, instead of trying to
reverse your operations, ...

> g2.translate(-x, -y);
> g2.rotate(-r);


.... because this adds rounding errors.

[...]
> So, if there was a possibility to get the new coordinates of my polygon
> with the first solution (everything done with graphics2D),


There are no new polygon user space coordinates, since you have in no
way translated the polygon. You have changed the origin and rotation of
the device space coordinate system in which the polygon is drawn. Within
that coordinate system the polygon user space coordinates are absolutely
the same as before.

So what is it what you really want?

/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/...g/java/gui/faq
http://www.uni-giessen.de/faq/archiv....java.gui.faq/
 
Reply With Quote
 
 
 
 
Chantal
Guest
Posts: n/a
 
      01-24-2006
Hello Thomas,

Thanks you for your answer.

How to get original values ?

What I wanted was to try to get the coordonnates of the rotated polygon
but if it's only the device space system coordinates which is changed,
I don't have certainly the possibility to get it. I'll try another way.

Thanks again Thomas, )

Chantal

 
Reply With Quote
 
Chantal
Guest
Posts: n/a
 
      01-24-2006
Re,

I get it I think : g2.getTransform().getTranslateX();

etc...

Thanks again

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-24-2006
On 24 Jan 2006 04:59:15 -0800, "Chantal" <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>But I would like to know if it's possible to get the new coordinates of
>the polygon, I mean after the rotation and translation are done.


See http://mindprod.com/jgloss/affinetransform.html#MANUAL
It shows you how to transform an individual point.

Unfortunately that method requires you do the matrix multiply twice,
once for the polygon for drawing and once for discovering where the
transform put the points.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting X, Y coordinates of objects with javascript for netscape 8 abuhijleh Javascript 3 10-16-2005 08:54 AM
Getting Mouse coordinates in a DIV Jonne Javascript 4 02-26-2005 02:56 AM
Getting Jpeg Image Coordinates Janani via DotNetMonster.com ASP .Net 1 01-20-2005 03:23 PM
Converting canvas coordinates to window coordinates in tkinter......... Suresh Kumar Python 0 07-04-2003 10:14 AM
Converting canvas coordinates to window coordinates....... Suresh Kumar Python 0 07-03-2003 04:53 AM



Advertisments