I need help with a little equation solving problem

BlitzMax Forums/BlitzMax Programming/I need help with a little equation solving problem

Reda Borchardt(Posted 2011) [#1]
As part of a little project that I am working on, I have the following math challenge to solve:

I use the following two lines to convert 3D into screen space (simplified).

xScreenCoord = (x-z) * Math.cos(0.46)
yScreenCoord = (y+(x-z) * Math.sin(0.46)

My challenge is to produce a solution that I can feed xScreenCoord, yScreenCoord and the 'y' component into to get 'x' and 'z' values.

PS: Please don't suggest to use lookup tables. The app supports dimetric projections and a certain level of rotation around y. All the functions are based on the skeleton above and changing it would be a massive headache.

Your help would be really appreciated.


Warpy(Posted 2011) [#2]
Rearrange the two equations:

x-z = xScreenCoord/Math.cos(0.46)
x-z = yScreenCoord/Math.sin(0.46) - y

So it has to be the case that

xScreenCoord/Math.cos(0.46) = yScreenCoord/Math.sin(0.46) - y = A

for some value A.

So we have

x-z = A
x-z = A

which isn't enough to solve for x and z. So it isn't possible. You can pick an arbitrary value of x or z and work out the other one, but there isn't a unique solution.


Reda Borchardt(Posted 2011) [#3]
Thank Warpy.

IRC #MATH on EFNET solved it :)

x=(Math.cos(0.46)*(v-y)+Math.sin(0.46)*u)/(2*Math.cos(0.46)*Math.sin(0.46))
z=(Math.cos(0.46)*(v-y)-Math.sin(0.46)*u)/(2*Math.cos(0.46)*Math.sin(0.46))

u stands for xScreenCoord and v for yScreenCoord

Last edited 2011


Warpy(Posted 2011) [#4]
Ah, I misread the brackets! You're missing a right bracket on the second equation.


Reda Borchardt(Posted 2011) [#5]
Yes indeed, the second one isn't balanced and missing a closing bracket at the end.

Here is the equation in action: http://www.isowerk.com/dev/v1/src/examples/test1.html

It's a HTML5 test page that works anywhere except IE8 and below.


Kryzon(Posted 2011) [#6]
That demo is freaking hot.


Warpy(Posted 2011) [#7]
Ah no, I was right the first time with what you'd written. You meant to put (x+z) in the second equation, not (x-z).