4th July 2003 19:26 UTC
Sphere Intersection prob
Sphere Intersection Problem:
Ok, I have been playing a lot with dm's these days and I have treied to make multiple cylinders and spheres in one dm. Found that it was much easier to play around with cylinders and sphere's than planes. But, there is a problem here about the sphere intersection.
The ugly edges are too much, is there any way we can use alpha blending to blacken out the edges?
And then is there any way to enter the cylinders?
Here's what is required:
(ox,oy,oz) origin
(rx,ry,rz) rotation angles
sx,sy,sz,cx,cy,cz sines and cosines of rx,ry and rz
a,b,c - co-efficient of the three terms of the quadratic equation of the cylinder/sphere
k1,k2 - for cylinder
k3 - inner sphere
k4 - outer sphere
to solve a quadratic equaltion ax^2+bx+c=0
x = (-b +/- sqrt( sqr ( b )- 4 ac ) / 2a is used.
there are a lot of temperory vars used.
Init:
pi=acos(-1)
Frame:
t=t+.001+ti*.1;ti=ti*.9;
ox=sin(t)*.1;
oy=sin(t)*cos(t)*.15;
oz=cos(t)*.1;
rx=atan2(ox,sqr(oy)+sqr(oz));
ry=-atan2(ox,oz);
rz=rx*ry*ox*oy*oz+sin(t*.3)*pi;
sx=sin(rx);sy=sin(ry);sz=sin(rz);
cx=cos(rx);cy=cos(ry);cz=cos(rz);
af=max(h,w)/min(h,w);
Beat:
ti=(abs(getosc(0,0,0)*400)%10)*.2
Point:
y=if(above(h,w),y*af,y);
x=if(above(w,h),x*af,x);
¤ Rotate ray;
dx1=x*cz-y*sz;
dy1=x*sz+y*cz;
dy2=dy1*cx-sx;
dz2=dy1*sx+cx;
dx3=dx1*cy-dz2*sy;
dz2=dx1*sy+dz2*cy;
¤temp variables, save time;
dx1=sqr(dx3);dy1=sqr(dy2);dz1=sqr(dz2);
¤calculate cylinfer 1, equation sqr(x)+sqr(y)=0.7*0.7;
a=dx1+dy1;
b=2*(dx3*ox+dy2*oy);
c=sqr(ox)+sqr(oy)+.49;
D=sqr(b)-4*a*c;
k1=(-b+sqrt(d))/(2*a);
¤calculate cylinfer 2, equation sqr(x)+sqr(z)=0.7*0.7;
a=dx1+dz1;
b=2*(dx3*ox+dz2*oy);
c=sqr(ox)+sqr(oz)+.49;
D=sqr(b)-4*a*c;
k2=(-b+sqrt(d))/(2*a);
¤calculate inner sphere, equation: sqr(x)+sqr(y)+sqr(z)=sqr(0.9);
a=dx1+dy1+dz1;
b=2*(dx3*ox+dy2*oy+dz2*oz);
c=sqr(oz)+sqr(oy)+sqr(oz)-.9;
D=sqr(b)-4*a*c;
k3=(-b+sqrt(d))/(2*a);
¤calculate outer sphere, equation: sqr(x)+sqr(y)+sqr(z)=sqr(2);
a=dx1+dy1+dz1;
b=2*(dx3*ox+dy2*oy+dz2*oz);
c=sqr(oz)+sqr(oy)+sqr(oz)-4;
D=sqr(b)-4*a*c;
k4=(-b+sqrt(d))/(2*a);
k1=if(below(k1,0),1000,k1);
k2=if(below(k2,0),1000,k2);
k3=if(below(k3,0),1000,k3);
k4=if(below(k4,0),1000,k4);
¤ order - inner sphere - cylinders - outer sphere;
¤ k1, k2 - cylinders, k3 - inner sphere, k4 - outer sphere;
k=min(max(max(k1,k2),k3),k4);
ix=k*dx3+ox;
iy=if(equal(k,k1)+equal(k,k3)+equal(k,k4),dy2*k+oy,dz2*k+oz);
iz=if(equal(k,k1)+equal(k,k3)+equal(k,k4),dz2*k+oz,dy2*k+oy);
rad=if(equal(k,k3),.9,2);
r=if(equal(k,k3),1,.5);
¤problem zone;
x=if(equal(k,k3)+equal(k,k4),atan2(iz,ix)/pi*1.4,asin(sin(atan2(ix,iy)))*.954);
y=if(equal(k,k3)+equal(k,k4),asin(iy/rad)*4/pi,iz);
¤end of problem zone;
¤ cool wrap by UnConeD;
x=asin(sin(x*pi*.5))*2/pi;
y=asin(sin(y*pi*.5))*2/pi;
---------------------------------
rectangular coords on, blend off, wrap OFF
Ohh...and use any kind of a picture as a texture, as I havent made any.