Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > From AffineTransform to PerspectiveTransform

Reply
Thread Tools

From AffineTransform to PerspectiveTransform

 
 
Andrew Thompson
Guest
Posts: n/a
 
      10-23-2008
I have been trying, unsuccessfully over the last few days,
to create a custom AffineTransfrom that creates the effect
of seeing a flat surface at an angle, a 'perspective view'.

My efforts so far have been abysmal. I tried extending
AffineTransform
and overriding the transform(Point2D,Point2D) method, but is was
not getting called.. I went on to override every single transform()
method I could find, but *none* of them are getting called.

Questions.
1) Is it possible to create a perspective view of an object using
just (the inbuilt transforms) shear, scale, translate..?
(I'm thinking 'no'.)
2) Is an AffineTransform the way to go with this, or am I missing
how they are supposed to be used?
3) Does anybody have an insight into why my overridden methods
were not getting called? (Yes, yes. I know a code example could
help here, but I am hoping there is something I missed that another
person has solved previously.)

--
Andrew T.
pscode.org
 
Reply With Quote
 
 
 
 
Harold Yarmouth
Guest
Posts: n/a
 
      10-23-2008
Peter Duniho wrote:
> On Wed, 22 Oct 2008 19:49:52 -0700, Andrew Thompson
> <(E-Mail Removed)> wrote:
>
>> I have been trying, unsuccessfully over the last few days,
>> to create a custom AffineTransfrom that creates the effect
>> of seeing a flat surface at an angle, a 'perspective view'.
>>
>> My efforts so far have been abysmal. I tried extending
>> AffineTransform
>> and overriding the transform(Point2D,Point2D) method, but is was
>> not getting called.. I went on to override every single transform()
>> method I could find, but *none* of them are getting called.
>>
>> Questions.
>> 1) Is it possible to create a perspective view of an object using
>> just (the inbuilt transforms) shear, scale, translate..?
>> (I'm thinking 'no'.)

>
> I'm thinking no. My geometry is a little rusty these days, but my
> recollection is that an affine transformation by definition can't do
> this.


Well, actually ...

sort-a.

http://en.wikipedia.org/wiki/Transfo...ive_projection

I don't think this can be done with java.awt.geom.AffineTransform, though.
 
Reply With Quote
 
 
 
 
John B. Matthews
Guest
Posts: n/a
 
      10-23-2008
In article <gdpv7f$h9p$(E-Mail Removed)>,
Harold Yarmouth <(E-Mail Removed)> wrote:

> Peter Duniho wrote:
> > On Wed, 22 Oct 2008 19:49:52 -0700, Andrew Thompson
> > <(E-Mail Removed)> wrote:
> >
> >> I have been trying, unsuccessfully over the last few days,
> >> to create a custom AffineTransfrom that creates the effect
> >> of seeing a flat surface at an angle, a 'perspective view'.
> >>
> >> My efforts so far have been abysmal. I tried extending
> >> AffineTransform
> >> and overriding the transform(Point2D,Point2D) method, but is was
> >> not getting called.. I went on to override every single transform()
> >> method I could find, but *none* of them are getting called.
> >>
> >> Questions.
> >> 1) Is it possible to create a perspective view of an object using
> >> just (the inbuilt transforms) shear, scale, translate..?
> >> (I'm thinking 'no'.)

> >
> > I'm thinking no. My geometry is a little rusty these days, but my
> > recollection is that an affine transformation by definition can't do
> > this.

>
> Well, actually ...
>
> sort-a.
>
> http://en.wikipedia.org/wiki/Transfo...ive_projection
>
> I don't think this can be done with java.awt.geom.AffineTransform, though.


You might look at PerspectiveTransform:

<http://java.sun.com/products/java-me...jai-apidocs/ja
vax/media/jai/PerspectiveTransform.html>

--
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/
 
Reply With Quote
 
Harold Yarmouth
Guest
Posts: n/a
 
      10-24-2008
Peter Duniho wrote:
> On Thu, 23 Oct 2008 06:45:59 -0700, Harold Yarmouth
> <(E-Mail Removed)> wrote:
>
>>> I'm thinking no. My geometry is a little rusty these days, but my
>>> recollection is that an affine transformation by definition can't do
>>> this.

>>
>> Well, actually ...
>>
>> sort-a.
>>
>> http://en.wikipedia.org/wiki/Transfo...ive_projection
>>
>> I don't think this can be done with java.awt.geom.AffineTransform,
>> though.

>
> Then why did you say "sort-a"? My statement was specifically about
> affine transformations, not transforms in general.
>
> In what way does the perspective projection matrix relate to my
> statement about affine transformations?


Because the perspective projection trick discussed there uses an affine
transform in a higher-dimensional space "under the hood".
 
Reply With Quote
 
Harold Yarmouth
Guest
Posts: n/a
 
      10-24-2008
Peter Duniho wrote:
> On Thu, 23 Oct 2008 20:03:55 -0700, Harold Yarmouth
> <(E-Mail Removed)> wrote:
>
>>> In what way does the perspective projection matrix relate to my
>>> statement about affine transformations?

>>
>> Because the perspective projection trick discussed there uses an
>> affine transform in a higher-dimensional space "under the hood".

>
> Where? Please be more specific.
>
> It's true that a matrix transformation is used. But by definition, it's
> not an affine transform.
>
> Are you perhaps being misled


Is there a reason for your less-than-civil attitude here?

Matrix transformations are, by definition, affine transforms in the
space of the same dimensionality as the matrix. In fact they're the
subset of linear transforms, affine transforms that don't include any
translation component.

Indeed, there is a one-to-one correspondence between linear operators on
an n-dimensional vector space and nxn matrices, given a particular
ordered basis for the vector space.

The transformation in the lower-dimensional space that is produced is
not affine, but it is produced by doing a linear transformation in a
higher-dimensional space and then projecting down in a specific (and
non-affine) way.

The linear transformation in the higher-dimensional space can help
effect a translation as well as a perspective transform in the lower.
Indeed, it can induce any
affine-transformation-followed-by-perspective-transformation from what
I've seen.

Now, if you're done pointlessly nit-picking other peoples' attempts to
be helpful ...
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      10-24-2008
On Oct 24, 12:59*am, "John B. Matthews" <(E-Mail Removed)> wrote:

> You might look at PerspectiveTransform:
>
> <http://java.sun.com/products/java-me...jai-apidocs/ja
> vax/media/jai/PerspectiveTransform.html>


That seems to do what I need. Even better is that it
also offers the inverse transform - which is what I
ultimately want - the ability to grab an image of a
perspective view of some 'flat' document or painting
and *remove* the warping from the perspective view.

I've finally found a good reason to delve into JAI
(yeah sure, the vastly increased range of formats
that JAI offers would be funky, but that was never
vital to my projects).

Thanks also to the other contributors. I am reading
the ongoing discussion with interest, since I do not
have a great deal of experience with / knowledge of
transforms (though I'm OK at geometry, which is why I
thought I'd try writing one, failing finding an existing
class to do it for me).

--
Andrew T.
PhySci.org
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      10-24-2008
In article
<(E-Mail Removed)>,
Andrew Thompson <(E-Mail Removed)> wrote:

> On Oct 24, 12:59*am, "John B. Matthews" <(E-Mail Removed)> wrote:

[...]
> Thanks also to the other contributors.


Thanks, too.

> I am reading the ongoing discussion with interest, since I do not
> have a great deal of experience with / knowledge of transforms
> (though I'm OK at geometry, which is why I thought I'd try writing
> one, failing finding an existing class to do it for me).


I've used the results, as found in Java, GL and Quartz, but I'm weak
on the algebra. I see the correspondence between an affine transform
using homogeneous coordinates and the Java class AffineTransform:

<http://en.wikipedia.org/wiki/Transfo...e_transformati
ons>
<http://java.sun.com/javase/6/docs/ap...neTransform.ht
ml>

Now I compare the perspective transform with the corresponding Java
implementation, but I'm having trouble reconciling the 4D matrix in
the former with the 3D matrix in the latter:

<http://en.wikipedia.org/wiki/Transfo...ective_project
ion>
<http://java.sun.com/products/java-me...s/jai-apidocs/
javax/media/jai/PerspectiveTransform.html>

I'd be grateful is anyone can elaborate.

--
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/
 
Reply With Quote
 
Harold Yarmouth
Guest
Posts: n/a
 
      10-25-2008
Peter Duniho wrote:
> On Thu, 23 Oct 2008 20:23:10 -0700, Harold Yarmouth
> <(E-Mail Removed)> wrote:
>
>> Is there a reason for your less-than-civil attitude here?

>
> Any perception of "less-than-civil" is strictly in your own head.


I disagree. You have been brusque and slightly rude. Particularly with
this last, personal comment about something being all in my head.

>> Matrix transformations are, by definition, affine transforms in the
>> space of the same dimensionality as the matrix. In fact they're the
>> subset of linear transforms, affine transforms that don't include any
>> translation component.

>
> AffineTransform most certainly does "include any translation
> component". If you want to argue that a true affine transform doesn't,
> fine with me.


I don't, and I don't like it when people try to put words in my mouth as
an excuse to blast me in public. What is your problem with me, anyway?
It's apparently personal. Yet I've never interacted with you before this
thread, so how the hell can it be?

I said, of course, that the subset of affine transforms called linear
transforms are those that don't have translation components.

You even quoted the paragraph where I said it.

> As I said, my geometry and matrix math is a bit rusty


Then perhaps you shouldn't jump to criticize that of other posters.
Whatever your beefs with those posters.

>> Indeed, there is a one-to-one correspondence between linear operators
>> on an n-dimensional vector space and nxn matrices, given a particular
>> ordered basis for the vector space.
>>
>> The transformation in the lower-dimensional space that is produced is
>> not affine, but it is produced by doing a linear transformation in a
>> higher-dimensional space and then projecting down in a specific (and
>> non-affine) way.

>
> That's fine.


And that's what I originally said that you originally took issue with.

> But irrelevant to the AffineTransform in Java, which doesn't include
> those higher dimensions.


Which I pointed out myself in the first post that you attacked.

I was also pointing out, though, that it is not entirely true that
perspective transforms cannot be accomplished using affine transforms,
the way somebody had indicated. I was pointing out that perspective
transforms in a low dimensional space are quite often accomplished using
affine (indeed, linear) transforms in a higher dimensional space. Though
Java's AffineTransform class cannot be directly used to do this.

Someone else posted to mention that JAI contains a PerspectiveTransform
class in its API that does work that way under the hood.

>> Now, if you're done pointlessly nit-picking other peoples' attempts to
>> be helpful ...

>
> Um. You're a fine one to be speaking of nit-picking, yourself having
> started the entire nit-picking part of this thread.


I was pointing out something that I thought was interesting, and that
clarified previous discussion.

You were posting solely for the purpose of being rude to another person
online, as near as I can tell, and far from clarifying anything you have
muddied the waters, particularly with your latest post that actually
attempts to stuff words in my mouth that are approximately opposite to
what I'd actually said.

The contrast could not be much more stark.

(Oh, and a helpful hint for the future: when trying to stuff words in
someone's mouth, quoting the text of what they actually said tends to
undermine your effectiveness.
 
Reply With Quote
 
Harold Yarmouth
Guest
Posts: n/a
 
      10-25-2008
Lew wrote:
> Peter Duniho wrote:
>>> Are you perhaps being misled

>
> Harold Yarmouth wrote:
>> Is there a reason for your less-than-civil attitude here?

>
> One would consider a dry, objective tone ...


Are you reading the same posts that I am? His tone is quite clearly
confrontational in the posts that I am referencing. "Are you being
misled?", this or that "is strictly in your own head", something "most
certainly does" something that I never claimed it didn't do, and so forth.

At best, he is skimming my posts without reading them carefully, forming
snap judgments, and then publicly claiming that I said or implied things
other than what I actually did say.

But his attitude reminds me of how people sound when they don't like
someone, which makes me suspect that (for some reason I can't begin to
fathom, given that our history of interaction is about three days old
and consists of about three Usenet posts each) Peter has developed a
personal beef with me and, unfortunately, is being influenced by this to
act boorish towards me in public and not solely in private.
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      10-25-2008
In article <(E-Mail Removed)>,
"John B. Matthews" <(E-Mail Removed)> shamelessly follows up to
his own post:

> Now I compare the perspective transform with the corresponding Java
> implementation, but I'm having trouble reconciling the 4D matrix in
> the former with the 3D matrix in the latter:
>

<http://en.wikipedia.org/wiki/Transfo...tive_projectio
n>
<http://java.sun.com/products/java-me...jai-apidocs/ja
vax/media/jai/PerspectiveTransform.html>
>
> I'd be grateful is anyone can elaborate.


IIUC, the PerspectiveTransform uses homogeneous coordinates internally
in a vector space having an additional dimension:

<http://en.wikipedia.org/wiki/Homogen...n_computer_gra
phics>

[Instead of homogeneous, 'of the same kind,' the API uses the term
homogenous, 'having a common descent.']

--
John B. Matthews
trashgod at gmail dot com
http://home.roadrunner.com/~jbmatthews/
 
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
Why does AffineTransform not work on JTextPane? fiziwig Java 10 08-14-2006 08:51 AM
AffineTransform, RescaleOp and Bilinear hint news.skynet.be Java 0 03-25-2005 12:00 PM
AffineTransform substitute for 1.1 jdk? SPG Java 0 03-04-2005 12:25 PM
AffineTransform rotation question hilz Java 2 12-17-2004 07:45 PM
Problem using AffineTransform Rick Java 2 10-08-2003 10:46 AM



Advertisments