Archive: My lens problem


27th September 2002 21:38 UTC

My lens problem
Some of you might know this from DA, but nobody actually solved the problem there, and since all you math geniuses appear to be here, I decided to post my problem here. The idea to create what you when you hold a orb-like lens above a material (the background here).

I wanted to make a physically correct lens with the formula:

sin(entry angle)
----------------- = constant
sin(output angle)

This is the formula for light going trough different translucent materials.

I created a dynmov with the following code:

init:
bi=1.3;dt=1;df=1;si=1;

frame and beat don't mather, they just change the x1 and y1 values.

pixel:
x=x*dt+sin(x1);y=y*dt+sin(y1);
l=max(si-sqrt(x*x+y*y),0);
r=atan2(y,x);
xdti=cos(r)*-l*pi/2;xdtu=asin(sin(xdti)/bi);x2=tan(xdtu)*(l*2);
ydti=sin(r)*-l*pi/2;ydtu=asin(sin(ydti)/bi);y2=tan(ydtu)*(l*2);
rx=atan2(x2,l*2);ry=atan2(y2,l*2);
xdti2=rx*l-xdtu;xdtu2=asin(sin(xdti2)/bi);
ydti2=ry*l-ydtu;ydtu2=asin(sin(ydti2)/bi);
x=x-tan(xdtu2)*(0.5-l+df)-sin(x1);
y=y-tan(ydtu2)*(0.5-l+df)-sin(y1);

Anyway the problem is that when you change either the si (size of lens) or bi (abb******on for dutch word brekingsindex, fraction index) in the init, the lens go weird.

The si-problem is seen the best: If you change it to two, it gets totally weird.
The bi-problem is more subtle: The fraction of the light passing the lens should get larger if you enlarge bi, but it gets smaller!

I hope you understand what I'm saying and if don't know what I did with a certain piece of code, you can ask. Actually, I encourage you to ask.

I also attached a preset, where an advanced version of the (bad) lens is used. It requires the convoltion ape. It''s actually a quite cool preset, it contains in text the first ten article of the Human Rights Declaration.


27th September 2002 22:32 UTC

Remember that Movements/DM's work backwards: you specify source coordinates for a certain target point.


28th September 2002 14:07 UTC

Look like you hitting a limit with si and it started to lop back on itself. Something you're doing with l somewhere.

I hate reading other peoples' code. Never can really figure it out.


1st October 2002 23:11 UTC

Since this a light effect wouldn't it be best to do some raytracing.
You use your background as if it were a plane then raytrace through the space holding the orb, if it doesn't intersect the orb we do nothing, otherwise we do a sphere intersection test and setup a new ray using your lens forumla which then goes on to hit the background to find what point you would see through the lens. (if that makes sense)

I'm only starting to mess around with implementing raytracing in a dm but when I get a bit more comfortable with it (I'm still just screwing with planes and spheres) I'll probably give it ago for you. :)