Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to distort or map a given jpg so it looks 3D as in the following youtube video: http://www.youtube.com/watch?v=IfCCUd8mFtg. I usually use conformal mapping (a complex function) to do my distortions. Can you help me with figuring out which function to use for this?

share|improve this question
    
Neat presentation about this type (I think) of projection: facultyfp.salisbury.edu/despickler/personal/Resources/… –  Pickett Dec 6 '13 at 18:42
    
qr code on shopping cart –  Kuba Dec 6 '13 at 18:49
    
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! –  belisarius 4 hours ago

1 Answer 1

lin[cam_, obj_][t_] := cam  t + (1 - t) obj
s[cam_, obj_] := First@Solve[lin[cam, obj][t][[3]] == 0, t];
tr[cam_, obj_] := lin[cam, obj][t] /. s[cam, obj] // FullSimplify

And that's it: tr[ ] i your transformation function. Let's test it with a Rubik's cube, simulating the video you linked. The following boring part is building the cube. We will make only three faces, since the rest aren't visible.

(*The following is a face with random colors*)
d = .05; col := RandomChoice[{Red, Orange, Green, White, Yellow, Blue}];
face := Table[{col, EdgeForm[Black], Polygon[{{i + d, j + d, 0}, {i + 1 - d, j + d, 0}, 
                                              {i + 1 - d, j + 1 - d, 0}, {i + d, j + 1 - d, 0}}]}, 
             {i, 0, 2}, {j, 0, 2}]

(*Now we build a "3-faced-cube"*)
m = RotationTransform[Pi, {0, 1, 0}, 3/2 {1, 0, 1}];
cube = Table[(face /. Polygon[x_] :> Polygon[m /@ (RotateLeft[#, i] & /@ x)]), {i, 0, 2}];
Graphics3D[cube, Axes -> True, Lighting -> {{"Ambient", White}}]

Mathematica graphics

And now (surprise!) we project the cube onto a sheet of paper using the function defined at the top. Let's see two views. First, the one faking a 3D view made by selecting the appropriate ViewPoint and ViewVector (meaning the camera position and direction):

Graphics3D[cube /. Polygon[x_] :> Polygon[tr[{10, -10, 10}, #] & /@ x], 
           Lighting -> "Neutral", ViewVector -> {{10, -10, 10}, {0, 3, 0}}, Boxed -> True]

Mathematica graphics

And now the "real" paper sheet for you to print it and make your own video :)

Framed@Graphics[cube /. (Polygon[x_] :> Polygon[tr[{10, -10, 10}, #] & /@ x]) /. 
                Polygon[x_] :> Polygon[Most /@ x]]

Mathematica graphics

Edit:

Raising and then lowering the camera:

enter image description here .

share|improve this answer
    
What are we looking at? How does it relate to what we see in the video? –  Pickett Dec 6 '13 at 20:51
1  
@Anon The dots on the z==0 plane are the 2-d projection for the front face and top face of the cube as you should draw them to fake the appearance for the camera at a certain position (cam in my code) –  belisarius Dec 6 '13 at 20:54
    
@Anon Perhaps it's clear now :) –  belisarius Dec 7 '13 at 6:28
    
Much better! Very nice. –  Pickett Dec 7 '13 at 11:05
    
Love the simplicity of this answer. A published a related demonstration some time ago demonstrations.wolfram.com/… hth –  MaTECmatica Dec 9 '13 at 9:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.