DEMO.DESIGN
Frequently Asked Questions
 
оглавление | demo party в ex-СССР | infused bytes e-mag | новости от ib/news | другие проекты | письмо | win koi lat

следующий фpагмент (2)
- Usenet echoes (21:200/1) -------------------------- COMP.GRAPHICS.ALGORITHMS - Msg : 20 of 32 From : andres@dpt-info.u-strasbg.fr 2:5030/144.99 30 Aug 94 15:52:10 To : All 04 Oct 93 03:31:16 Subj : (1) sphere algorithm without gaps -------------------------------------------------------------------------------- Some of you have asked more details so let's go: First of all, I will not discuss about theoretical points. I will just present the algorithms and the advantages/drawbacks... 1) The sphere generation algorithm is based on the circle generation algorithm. The circle is defined by the diophantine equations : x^2 + y^2 E [(R-1/2)^2,(R+1/2)^2[, where x,y,R are integers. This circles have some advantages : - efficient algorithm (as you will see), generalizes Bresenham's circles, circles with same center and integer radii pave the plane, immediate point localisation (to know if a point is inside, outside or belongs to a circle is trivial to determine).. Algorithm : Circle_sphere (Rcurrent,cstmin,cstmax,z : integer) begin x:=0; y:=Rcurrent; d:=Rcurrent; cstlocalmin := Rcurrent^2+R+cstmin; cstlocalmax := Rcurrent^2+R+cstmax; while (y>=x) do if ((d>=cstlocalmin) and (d<cstlocalmax)) then plot48voxels(Xo,Yo,Zo,x,y,z) /* 48-symmetry for the sphere*/ endif if (d>2*x) then d:=d-2*x-1; x:=x+1; else if (d<=2*(Rcurrent-y)) then d:= d+2*y-1; y:=y-1; else d:=d+2*(y-x-1); x:=x+1; y:=y-1; endif endwhile end I hope I haven't done any mistake by retiping this algo. Try it to generate circles before use it for spheres. It is easy to see what are the elements who not correpond to a circle generation algorithm. The circle generation algorithm can be improved, but this is another story. The sphere algorithm is based on the following consideration : if x^2+y^2+z^2 = n, then x^2+y^2 = n-z^2. we know how to calculate the value x^2+y^2 for a certain number of values, the values that define a circle : just one comment before giving the sphere algorithm : the following algorithm is given in non-optimized version for length reasons. I'll give some hints at the end to do that. Basic-Sphere Algorithm (Xo,Yo,Zo,R : integer) begin for z:=0 to R do Rmin := Givemin(z,R); Rmax := givemax(z,R); cstmin := z^2-R^2-R; cstmax := cstmin+2*R; for Rcurr := Rmin to Rmax do circle_sphere(Rcurr,cstmin,cstmax,z); endfor endfor endalgo With the functions : Givemin(z,R : integer) Givemax(z,R : integer) begin begin rmin:=R; Arcmin:=R^2-R; rmax:=R; Arcmax:=R^2-R; mins:=Arcmin-z^2; maxs:=Arcmin+2*R-z^2; if (mins<0) then rmin:=0; while (maxs<Arcmax) do else while (mins<Arcmin) do max:=max-1; rmin:=rmin-1; Arcmax:=Arcmax-2*rmax Arcmin:=Arcmin-2*rmin endwhile endwhile return(rmax); endif endfunction return(rmin); endfunction If there are any problems, just call... Eric ANDRES
следующий фpагмент (3)|пpедыдущий фpагмент (1)
/* ** generate a pov spiral ** ** author unknown */ #include <stdio.h> #include <stdlib.h> #include <math.h> char *PovBoiler = "\ #include \"colors.inc\"\n\ //global_settings{ assumed_gamma 1}\n\ camera{ location <0,0,-145>look_at<0,0,0>}\n\ #declare SpiralTexture=texture{pigment{color Green}\n\ finish{metallic}rotate<0,0,90>}\n\ sphere{<0,0,0>15000 inverse texture{pigment{color NavyBlue}finish{ambient 1 diffuse 1}}}\n\ object{plane{z,962}rotate<-67,0,0>texture{pigment{\n\ bozo turbulence 1 color_map{[0 color Gray90]\n\ [0.1 color White ][0.25 color Gray95 ]\n\ [0.26 color Gray95]\n\ [0.3 color Gray80][0.7 color Gray70]\n\ [0.8 color Gray90][0.81 color Gold][0.83 color Clear][1 color Clear]}\n\ scale 400}\n\ finish{ambient 0.1 reflection 0.1}}no_shadow}\n\ object{plane{y,-210}rotate<10,0,0> texture{pigment{marble turbulence 1\n\ color_map{[0 color Green][0.41 color Maroon]\n\ [0.5 color DarkTurquoise][0.93 color Magenta]}\n\ scale 5}normal{waves 2 turbulence 1 scale 2}\n\ finish{ambient 1 diffuse 0 reflection rgb<0,0,1>}scale 392}}\n\ light_source{< 0,17,-45>color White}\n\ light_source{<-50,355,-4>color Gray80}\n\n"; #define RADIANS_PER_DEGREE 0.0174533 #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) double degrees_to_radians( double degrees ) { double angle; while( degrees >= 360 ) degrees -= 360; while( degrees < 0 ) degrees+=360; angle = RADIANS_PER_DEGREE * degrees; return angle; } double cosd( double x ) { double r = degrees_to_radians( x ); double r2 = cos( r ); return( r2 ); } double sind( double x ) { double r = degrees_to_radians( x ); double r2 = sin( r ); return( r2 ); } void rotate( double angle, double mag, double originx, double originy, double x1, double y1, double *x2, double *y2 ) { if( fabs( angle ) > 1e4 ) angle = 60; *x2 = mag * ( ( x1 - originx ) * cosd( angle ) + ( y1 - originy ) * sind( angle ) ) + originx; *y2 = mag * ( ( y1 - originy ) * cosd( angle ) - ( x1 - originx ) * sind( angle ) ) + originy; } int main( int argc, char *argv[] ) { FILE *fp; int npts = 0; double angle; double nx; double ny; double vx; double vy; double d1; double d2; double cylinder_radius; double nz = 0; double vz = 0; /* ** extremes */ double maxx; double minx; double maxy; double miny; double maxz; double minz; /* ** variables that control the spiral, ** i.e., things to screw around with... */ double angle_increment = 10; double radius = 1; double numcircs = 3; double tightness = 1.75; double growth = 1.02; fp = fopen( "killme.pov", "w" ); rewind( fp ); fprintf( fp, "%s\n\n\n", PovBoiler ); fprintf( fp, "#declare Spiral=blob{threshold 0.1\n" ); for( angle = 0; angle <= ( numcircs * 360); angle += angle_increment ) { nz = vz; rotate( angle, radius, 0, 0, 1, 1, &nx, &ny ); rotate( angle + angle_increment, radius, 0, 0, 1, 1, &vx, &vy ); d1 = fabs( nx - vx ); d2 = fabs( ny - vy ); cylinder_radius = sqrt( d1 * d1 + d2 * d2 ) / tightness; vz += ( 1.0 / ( 360.0 / angle_increment ) ) * numcircs * tightness; fprintf( fp, "cylinder{<%lf,%lf,%lf>,<%lf,%lf,%lf>%lf strength 2*%lf}\n", nx, ny, nz, vx, vy, vz, cylinder_radius, radius ); fprintf( fp, "sphere{<%lf,%lf,%lf>%lf strength 2*%lf}\n", vx, vy, vz, cylinder_radius, radius ); fprintf( fp, "sphere{<%lf,%lf,%lf>%lf strength 2*%lf}\n", nx, ny, nz, cylinder_radius, radius ); radius *= growth; if( !npts ) { minx = maxx = nx; miny = maxy = ny; minz = maxz = nz; } else { minx = MIN(minx, nx); maxx = MAX(maxx, nx); miny = MIN(miny, ny); maxy = MAX(maxy, ny); minz = MIN(minz, nz); maxz = MAX(maxz, nz); } ++npts; } fprintf( fp, "//extremes X(%g,%g) Y(%g,%g) Z(%g,%g)\n", minx, maxx, miny, maxy, minz, maxz ); fprintf( fp, "translate<%g,%g,%g>}\n", (maxx+minx)/-2.0, (maxy+miny)/-2.0, (maxz+minz)/-2.0 ); fprintf( fp, "object{Spiral scale 5 rotate <-90,0,0>texture{SpiralTe xture}no_shadow}\n" ); fclose( fp ); return( 0 ); }

Всего 2 фpагмент(а/ов) |пpедыдущий фpагмент (2)

Если вы хотите дополнить FAQ - пожалуйста пишите.

design/collection/some content by Frog,
DEMO DESIGN FAQ (C) Realm Of Illusion 1994-2000,
При перепечатке материалов этой страницы пожалуйста ссылайтесь на источник: "DEMO.DESIGN FAQ, http://www.enlight.ru/demo/faq".