Click to See Complete Forum and Search --> : 3D reverse equation

04-29-2002, 01:14 PM
I'm positioning an MC in three dimensional space using the following:

onClipEvent (load) {

sinY = cosY = 0.707;
cosX = 0.819;
sinX = 0.573;

x = 2;
z = -1;
y = -2;

// place moving block on screen appropriately

this._x = z * sinY + x * cosY;
this._y = y * cosX - (z * cosY- x * sinY) * sinX;


This is working fine. Now here's the problem. How can I achieve the reverse of this? How can I supply the equation with an MC's stage _x and _Y and have it figure out what the equivalent x,y and z is in the three dimensional space. Can this be done, or am I out of my tree?

thanks in advance,


05-01-2002, 11:58 AM
You have two equations and three unknowns - not good.

You'll need some other way to figure out one of the varibles to be solved for; any given point (_X,_Y) on the screen can correspond to any number of (x,y,z) points.

05-01-2002, 12:12 PM
thanks - time to go back to school I think :-)

I think I'm going to solve this one by realizing that I need to quantify all MCs within the 3d space that I have created, rather than trying to make some calculations based on 2D screen position, and some on 3D.

05-31-2002, 10:11 AM
I do a calculation like this. See my 3D engine at.


When you drag a new object the scene, or move an object already on the stage - it calculates (x,y,z) from (x,y). I always drag objects onto the z=0 plane. And dragging objects, z doesn't change. That's the trick.

Ed Mack
06-01-2002, 10:40 AM
Ok, I'm assuming that you are drawing in ISO?

Anyway, first work out the bounding box size of one ISO tile, and work out what one the x and y coords are one (Math.floor(y/isotileheight) ect..) And remember that number

Next, you have to find what region of the rectangle you are in. Imagine that there are 5 regions, the first is the shape of the iso tile, the other 4 are the triangles left around the 4 corners. Work out which reigion of iso tile the point is in (make a dummy off screen and hitTest the four bits, or use algebra) and if it's in the center one, the number's you worked out earlier (x/y of the rectangle) is the tile, if it is top left or bottom right, then subtract or add 1 to the x number from earlier, if it's the top right or bot left, add or subtract one from the y axis

Here's an image

06-02-2002, 12:20 AM
Originally posted by scootaboy
this._x = z * sinY + x * cosY;
this._y = y * cosX - (z * cosY- x * sinY) * sinX;

I suppose it is Isometric. The z value (z * cosY- x * sinY) isn't retained to do any perspective calculation or depth/z-buffering.

I found a piece of code I wrote a while back. I'm not sure it's any use to you. I don't use it any more. I can't even remember how it works - but looking at it, I think I know what's going on. The principle was that it went back from 3D coordinates to 2D coordinates. It assumed that the variables sinx,siny etc.. were already set, as you have set them. It undid the perspective transformation first (not applicable to you), then it undid the rotation:-

function unrotate(A,B,si,co) {K=si/co;return (A+K*B)/(K*si+co)}

function to3d(xx,yy,zz,i) {
// Z[i]=unrotate(zz1,-yy0,sinx,cosx)

I'm not sure whether this is equivalent, more complex or less complex than Ed's solution.

Ed Mack
06-02-2002, 06:12 AM
I think yours defines regions.. Probably the same sort of thing.