We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › How to calculate 3D cube based on 2D coordinates
Page Index Toggle Pages: 1
How to calculate 3D cube based on 2D coordinates (Read 643 times)
How to calculate 3D cube based on 2D coordinates
Jun 7th, 2009, 6:50am
 
This seemingly simple problem has me baffled on many different levels.

What I want (but have Photoshopped for now):
...

What is given:
> the red square is drawn by my motion detecting function that watches video input. (A, B)
> a transformed 3D matrix by a given rotation & translation

What I need:
> drawing(size & position) of a quad that corresponds to a square transformed by the given matrix that exactly encompasses this 2D square. For instance the side 1265 of the white cube in the image.  

How do I calculate the position & size of the cube based on coordinates in 2D? It seems I'm in need of an inverted screenX function that returns the 3D coordinates of my 2D rectangle dimensions?

Yikes.. I feel like popping my own matrix...
Re: How to calculate 3D cube based on 2D coordinates
Reply #1 - Jun 7th, 2009, 10:00am
 
Rapatsk1 wrote on Jun 7th, 2009, 6:50am:
This seemingly simple problem has me baffled on many different levels.


Doesn't seem particularly simple to me.  Surely the points on your 2d rectangle could be represented by any number of xyz combinations in 3d space

To put it another way [thinking aloud...]
Looking at the ActionScript (2) animation book they used the following formula to calculate adjusted coordinates for 3D:

scale = fl/(fl+z)
(where fl = focal length)

So you get:

x = x1*(fl/(fl+z)
(where x = the 2d x coordinate based on x1 and z in 3d space).  If you're aiming to match a specific 2d x coordinate you have to re-arrange the formula...  But then you have a problem because both x1 and z are unknowns, so for any given value of x there are going to be many values you could put into x1 and z...
Re: How to calculate 3D cube based on 2D coordinates
Reply #2 - Jun 7th, 2009, 10:46am
 
Thanks for thinking along!

Interesting formula, will look into that..

As the perspective (fov) and the transformation of the cube are known, there really should be only one possibility. Actually, one only needs to know the size of the cube that fits the rectangle snuggily?
Page Index Toggle Pages: 1