Intersection Sphère Cône oblique
Posté : lun. 29 mars 2010, 11:27
Un petit délire personnel
Code : Tout sélectionner
size(250);
import graph3;
currentprojection=orthographic((20,17,6),up=Z);
currentlight=Viewport;
real lx=4, ly=2, thmin=.25, thmax=1, hmin=2, hmax=11;
triple S=(0,5,8);
path3 p=(lx,0,0)..(0,ly,0)..(-lx,0,0)..(0,-ly,0)..cycle;
triple f(pair t) {
real theta=t.x;
real k=t.y/S.z;
real x=relpoint(p,theta).x*(1-k)+S.x*k;
real y=relpoint(p,theta).y*(1-k)+S.y*k;
real z=t.y;
return (x,y,z);
}
surface s=surface(f,(thmin,hmin),(thmax,hmax),36,36,Spline),
sph=shift(0,0,S.z*.75)*scale3(3)*unitsphere;
draw(s,red);
draw(sph,orange);
limits((0,0,0),(lx+1,ly+1,S.z+2));
xaxis3("$x$",Arrow3);
yaxis3("$y$",Arrow3);
zaxis3("$z$",Arrow3);
draw(p,green);
dot(p^^S,2bp+blue);
for(int i=0; i<size(p);++i) draw(point(p,i)--S,dashed);
/////// INTERSECTION
triple[][] in;
guide3 ch;
int n=50;
for(int i=0; i<n; ++i){
path3 p=S--f((thmin+i*(thmax-thmin)/n,0));
in.push(intersectionpoints(p,sph));
}
for(int i=0; i<in.length; ++i){
if(in[i].length!=0){
ch=ch..in[i][0];
if(in[i].length==2) ch=in[i][1]..ch;
dot(in[i],2bp+green);
}
}
draw(ch..cycle,1bp+blue);