Image:Bolza surface projection.png
From Wikipedia, the free encyclopedia
Size of this preview: 600 × 600 pixels
Full resolution (800 × 800 pixels, file size: 876 KB, MIME type: image/png)
This is a file from the Wikimedia Commons. The description on its description page there is shown below.
|
[edit] Dettagli
Description |
Perspective projection of affine model of Bolza surface |
---|---|
Source |
self-made |
Date |
2007-11-20 |
Author | |
Permission (Reusing this image) |
CC-BY 3.0 |
[edit] Licensing
[edit] Source Code
The dirty C++ source generating code. Yuo need a good complex implementation, and a 3D point e 4D point implementation.
#include <stdio.h> #include <vector> #include <rcomplex.h> #include <srl/point3.h> #include <srl/point4.h> #include <triangle.h> using namespace srl; void projection( const point4d & p4, point3d & p3 ){ const double R = 4; p3.x() = p4.x() / ( R - p4.y() ); p3.y() = p4.z() / ( R - p4.y() ); p3.z() = p4.w() / ( R - p4.y() ); } int main() { const double N = 128; // Dimensione griglia parametrica del dominio const double minv = -2.0; // Intervallo di valori const double maxv = 2.0; const double maxnorm3 = 0.75; // Massima norma punti proiettati const double maxdist3 = 0.05; // Massima distanza percentuale bbox in r3 degli adiacenti const double OUTSCALE = 4; std::vector<point4d> pts4; std::vector<point3d> pts3; int i,j,k; // Generazione punti e proiezione std::vector<int> idx[2]; idx[0].resize(N*N); idx[1].resize(N*N); for(j=0;j<N;++j) { const double vj = minv+(maxv-minv)*j/(N-1); for(i=0;i<N;++i) { const double vi = minv+(maxv-minv)*i/(N-1); complex x(vi,vj); complex y[2]; radix( x*x*x*x*x -x, 2, y); for(int k=0;k<2;++k) { point4d p4(x.re(),x.im(),y[k].re(),y[k].im()); point3d p3; projection(p4,p3); idx[k][i+j*N] = -1; if(p3.norm()<maxnorm3) { idx[k][i+j*N] = pts3.size(); pts4.push_back(p4); pts3.push_back(p3); } } } } FILE * fp = fopen("bolza_surface.wrl","w"); fprintf(fp, "#VRML V1.0 ascii\nSeparator {\nMaterial {\nemissiveColor 1 1 1 \n}\n" "Sphere\n{\nradius -8\n}\n}\n" "Material {\ntransparency 0.5\n}\n" "Coordinate3 {\npoint [\n" ); for(i=0;i<pts3.size();++i) fprintf(fp,"%g %g %g,\n",pts3[i].x()*OUTSCALE,pts3[i].y()*OUTSCALE,pts3[i].z()*OUTSCALE); fprintf(fp, "]\n" "}\n" ); fprintf(fp, "IndexedFaceSet {\n" "coordIndex [\n" ); const double max3 = maxdist3*maxnorm3*2; for(i=0;i<N-1;++i) for(j=0;j<N-1;++j) { for(k=0;k<2;++k) { int a = idx[k][i+0+(j+0)*N]; int b = idx[k][i+1+(j+0)*N]; int c = idx[k][i+1+(j+1)*N]; int d = idx[k][i+0+(j+1)*N]; if(a!=-1 && b!=-1 && c!=-1 && d!=-1 && dist(pts3[a],pts3[b])<max3 && dist(pts3[b],pts3[c])<max3 && dist(pts3[c],pts3[d])<max3 && dist(pts3[d],pts3[a])<max3 ) { fprintf(fp,"%d,%d,%d,-1,\n",a,b,c); fprintf(fp,"%d,%d,%d,-1,\n",a,c,d); } else if(a!=-1 && b!=-1 && c!=-1 && dist(pts3[a],pts3[b])<max3 && dist(pts3[b],pts3[c])<max3 && dist(pts3[c],pts3[a])<max3 ) fprintf(fp,"%d,%d,%d,-1,\n",a,b,c); else if(b!=-1 && c!=-1 && d!=-1 && dist(pts3[b],pts3[c])<max3 && dist(pts3[c],pts3[d])<max3 && dist(pts3[d],pts3[b])<max3 ) fprintf(fp,"%d,%d,%d,-1,\n",b,c,d); else if(a!=-1 && c!=-1 && d!=-1 && dist(pts3[a],pts3[c])<max3 && dist(pts3[c],pts3[d])<max3 && dist(pts3[d],pts3[a])<max3 ) fprintf(fp,"%d,%d,%d,-1,\n",a,c,d); else if(a!=-1 && b!=-1 && d!=-1 && dist(pts3[a],pts3[b])<max3 && dist(pts3[b],pts3[d])<max3 && dist(pts3[d],pts3[a])<max3 ) fprintf(fp,"%d,%d,%d,-1,\n",a,b,d); } } fprintf(fp, "]\n}\n" "Material {\nemissiveColor 0 0 0.3\ntransparency 0.5\n}\n" "IndexedLineSet {\ncoordIndex [\n" ); for(i=0;i<N;i+=2) for(j=0;j<N-1;++j) { for(k=0;k<2;++k) { int a = idx[k][i+(j+0)*N]; int b = idx[k][i+(j+1)*N]; if(a!=-1 && b!=-1 && dist(pts3[a],pts3[b])<max3 ) fprintf(fp,"%d,%d,-1,\n",a,b); } for(k=0;k<2;++k) { int a = idx[k][j+0+i*N]; int b = idx[k][j+1+i*N]; if(a!=-1 && b!=-1 && dist(pts3[a],pts3[b])<max3 ) fprintf(fp,"%d,%d,-1,\n",a,b); } } fprintf(fp,"]\n}\n"); fclose(fp); return 0; }
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Dimensions | User | Comment | |
---|---|---|---|---|
current | 14:17, 20 November 2007 | 800×800 (876 KB) | Rocchini | ({{Information |Description=Perspective projection of affine model of Bolza surface |Source=self-made |Date=2007-11-20 |Author= Claudio Rocchini |Permission=CC-BY 3.0 }} ) |
File links
The following pages on the English Wikipedia link to this file (pages on other projects are not listed):