Image:Bolza surface projection.png

From Wikipedia, the free encyclopedia

Wikimedia Commons logo This is a file from the Wikimedia Commons. The description on its description page there is shown below.
Commons is a freely licensed media file repository. You can help.

[edit] Dettagli

Description

Perspective projection of affine model of Bolza surface

Source

self-made

Date

2007-11-20

Author

Claudio Rocchini

Permission
(Reusing this image)

CC-BY 3.0


[edit] Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation license, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation license".

Aragonés | العربية | Asturianu | Български | বাংলা | ইমার ঠার/বিষ্ণুপ্রিয়া মণিপুরী | Brezhoneg | Bosanski | Català | Cebuano | Česky | Dansk | Deutsch | Ελληνικά | English | Esperanto | Español | Eesti | Euskara | فارسی | Suomi | Français | Gaeilge | Galego | עברית | Hrvatski | Magyar | Bahasa Indonesia | Ido | Íslenska | Italiano | 日本語 | ქართული | ភាសាខ្មែរ | 한국어 | Kurdî / كوردی | Latina | Lëtzebuergesch | Lietuvių | Bahasa Melayu | Nnapulitano | Nederlands | ‪Norsk (nynorsk)‬ | ‪Norsk (bokmål)‬ | Occitan | Polski | Português | Română | Русский | Slovenčina | Slovenščina | Shqip | Српски / Srpski | Svenska | తెలుగు | ไทย | Türkçe | Українська | اردو | Tiếng Việt | Volapük | Yorùbá | ‪中文(中国大陆)‬ | ‪中文(台灣)‬ | +/-

Creative Commons License
Creative Commons Attribution icon
This file is licensed under the Creative Commons Attribution 3.0 Unported License. In short: you are free to distribute and modify the file as long as you attribute its author(s) or licensor(s). Official license

Català | Česky | Deutsch | English | Ελληνικά | Español | Français | 한국어 | Italiano | עברית | Lietuvių | Magyar | Nederlands | Polski | Português | Русский | Türkçe | ‪中文(繁體)‬ | +/-

You may select the license of your choice.


[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/TimeDimensionsUserComment
current14:17, 20 November 2007800×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 }} )
The following pages on the English Wikipedia link to this file (pages on other projects are not listed):