From AffineTransform to PerspectiveTransform

A

Andrew Thompson

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.)
 
H

Harold Yarmouth

Peter said:
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".
 
H

Harold Yarmouth

Peter said:
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 ...
 
A

Andrew Thompson

You might look at PerspectiveTransform:

<http://java.sun.com/products/java-media/jai/forDevelopers/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).
 
J

John B. Matthews

Andrew Thompson said:
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/Transformation_matrix#Affine_transformati
ons>
<http://java.sun.com/javase/6/docs/api/java/awt/geom/AffineTransform.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/Transformation_matrix#Perspective_project
ion>
<http://java.sun.com/products/java-media/jai/forDevelopers/jai-apidocs/
javax/media/jai/PerspectiveTransform.html>

I'd be grateful is anyone can elaborate.
 
H

Harold Yarmouth

Peter said:
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.
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.
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.
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. :)
 
H

Harold Yarmouth

Lew said:
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.
 
J

John B. Matthews

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/Transformation_matrix#Perspective_projectio
n>
<http://java.sun.com/products/java-media/jai/forDevelopers/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/Homogeneous_coordinates#Use_in_computer_gra
phics>

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

zerg

Harold said:
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?

Our "friend" Peter Duniho seems to behave the same way towards many
people, so it probably isn't personal. Just an attitude problem on his part.

Google Groups search for his posts in this newsgroup and you'll find
that he's gotten into virtual fisticuffs with myself, some guy named
Lew, some guy named Ben, and others, too, and that he's usually the one
that threw the first punch.

On the other hand, he posts a fair amount of non-hostile on-topic
material too.

All the same, it would be nice if he'd make the effort to refrain from
posting as Mr. Hyde and only post as Dr. Jekyll.
 
A

Arne Vajhøj

Peter said:
Hmmm...interesting. Yet another Aioe.net user who has some bizarre
sensitivity to perceived-but-nonexistent slights, who says things like
"put words in my mouth" when all I've done is reiterate what _you_
wrote, and who makes a point about saying "I've never interacted with
you before this thread".

What next? Are you going to threaten legal action because I've
besmirched your good name?

Sorry zerg/Twisted/Paul/Ben/Harold...I've had my fill. You'll have to
troll someone else this time.

Anyone want to try and predict the next name he will be using ?

Arne
 
A

Arne Vajhøj

zerg said:
Our "friend" Peter Duniho seems to behave the same way towards many
people, so it probably isn't personal. Just an attitude problem on his
part.

Why are you talking to yourself ?

Arne
 
H

Harold Yarmouth

Peter said:
[...]
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?

Hmmm...interesting. Yet another Aioe.net user who has some bizarre
sensitivity to perceived-but-nonexistent slights, who says things like
"put words in my mouth" when all I've done is reiterate what _you_
wrote, and who makes a point about saying "I've never interacted with
you before this thread".

What next? Are you going to threaten legal action because I've
besmirched your good name?

Sorry zerg/Twisted/Paul/Ben/Harold...I've had my fill. You'll have to
troll someone else this time.

What have you been smoking, and where can I get some too?
 
H

Harold Yarmouth

Arne said:
Anyone want to try and predict the next name he will be using ?

I thought this was a newsgroup for discussing Java, not for making crazy
theories about random people.
 
H

Harold Yarmouth

Lew said:
I am personally acquainted with when Peter gets "brusque" (good word,
BTW, even though it didn't apply

It did apply.
Let it go and stop the flame war, all right?

After you. You just insulted me yourself, and without cause.

Why are you, Peter, and Arne suddenly posting a lot of completely
off-topic posts and saying things about me that range from insulting to
just plain strange? Why was Peter confrontational towards me without any
apparent justification?

I'm here to discuss Java, not get into fights or make pointless
off-topic posts.

It's a shame the same apparently cannot be said for everybody who posts
here.
 
H

Harold Yarmouth

Arne said:
You will need a large harddrive to keep a killfile with all his
aliases !

I don't have any aliases. What do you think I am, some sort of spy?

Hardly. I'm just an ordinary Java programmer. Quite boring, really.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top