A Flash Developer Resource Site

# Thread: Calculate 3D Plane from 2D Projection

1. ## Calculate 3D Plane from 2D Projection

I'm basically trying to emulate Photoshop's Vanishing Point tool where you can define the 4 2D points and the 3D plane is calculated from that information, in terms of the rotation of the plane relative to x y and z axes.

So if you have an image like this one:

And you define the points of the four corners, maybe like this:

it would define the 3D plane that the surface must live on relative to the x y and z axes.

Researching this has led me to some tutorials on drawTriangles and Homographies, but they all seem to be focused on mapping bitmap data and I can't seem to find anything that defines a 3D plane itself.

Anyone have any experience with such a problem? Any pointers would be great appreciated.

2. I'm not sure there is a unique solution unless you know something about the geometry of the selected shape. Essentially, you need to solve for z for each point given a transformation which takes a 2d (x,y) to a 3d (x,y,z). The actual projection will make a difference. An orthographic projection would be pretty easy to do, since x and y will not change. But you'll probably want a perspective projection for photographs, and you'll probably need to parameterize that by the field of view.

Even assuming they are all 4 coplanar doesn't seem like it gives enough information, since you don't know the actual size of the object (it could be arbitrarily large and far away). I suppose you could solve it with an assumed scaling constant if you only care about orientation. I'm not sure if you need to assume that your 4 points describe a rectangle or not.

I'm just talking through this, actually. It's an interesting problem, but I don't know exactly how to approach it.

3. On a little further thought, here is what I think you'll need to do:

You do need to assume that your points describe a rectangle. You have two sets of lines which are parallel in 3d, but converge in the 2d projection. Going by your image, let's call your points R, G, Y, and B by their colors. You have RB and GY as parallels, and RG and BY as parallels. Find the intersection of RB and GY and also of RG and BY. If these intersection points exist, then their coordinates will tell you the orientation of the plane. Either or both may NOT exist if that dimension's orientation is parallel to the plane of projection (the flat image window we are looking through).

I'm not sure of the exact method of getting the final orientation from the coordinates of the perspective vanishing points, but I really feel like that's the right track. Given the nature of the problem and the values we're dealing with, I instinctually think the solution will involve trigonometric functions like arctan.

http://en.wikipedia.org/wiki/Cartesi...rdinate_system

im pretty sure your answer lies in the "Cartesian formulas for the plane" section... but im not sure I just glanced over it.

5. That article only describes what the cartesian coordinate system is, and a few various properties it has. His problem is not with the 3d coordinate space, or in defining a plane in that space, but rather with solving for a 3d plane given a 2d projection and a few external constraints.

It's a good article to peruse if you're less familiar with dealing with 3d points, though.

6. Thanks so much for the responses. I for some reason wasn't notified of your posts or I would have replied sooner.

5TonsOfFlax, I dig where your going with this and I'll have to explore it in more detail. For the project, I actually had to settle for a workaround, but this problem has been gnawing at the back of my mind ever since.

I'm fine with disregarding scaling info. I even tried a system of equations assuming the blue corner was at z=0 in an attempt to simply things. Unfortunately I've made no progress. I'm convinced that a homography transformation is the key (http://en.wikipedia.org/wiki/Homography), but the matrix math is pretty deep, and even if I successfully calculate the homography, extracting the plane rotation from that is still a mystery.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap