File:Duopyramid.png

From testwiki
Jump to navigation Jump to search
    Original file (1,000 × 1,360 pixels, file size: 972 KB, MIME type: image/png)

    This file is from Wikimedia Commons and may be used by other projects. The description on its file description page there is shown below.

    Summary

    Description
    English: Stereographic projection of 6-4 Duopyramid (blu) with its dual Duoprism (phantom red). In the last row, the Duopyramid is projected by a direction perpendicular to the first one; so the two parameters (6,4) seem to be reversed. Indeed, asymmetry is due to the projection: the two parameters are symmetric in 4D.
    Date
    Source Own work
    Author Claudio Rocchini

    Licensing

    I, the copyright holder of this work, hereby publish it under the following license:
    w:en:Creative Commons
    attribution share alike
    This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
    You are free:
    • to share – to copy, distribute and transmit the work
    • to remix – to adapt the work
    Under the following conditions:
    • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
    • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.

    Source Code

    The source code needs some implementation of point3 and point4.

    /* Duopyramid VRML generator
     * (C) 2012-2013 CC-By 3.0 Claudio Rocchini
     */
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include "point3.h"
    #include "point4.h"
    
    const double PI = 3.1415926535897932384626433832795;
    const double S = 100;
    const double K1 = 0.03;
    const double K2 = 0.06;
    	
    static void draw_sphere( FILE * fo, const point3 & p, double r ) {
    	fprintf(fo,
    		"Separator{\n"
    		"\tTranslation { translation %g %g %g }\n"
    		"\tSphere { radius %g }\n"
    		"}\n"
    		,p.x*S,p.y*S,p.z*S,r*S
    	);
    }
    		
    static void draw_edge( FILE * fo, const point3 & p1, double r1, const point3 & p2, double r2 ) {
    	point3 d = p2-p1; double l = lenght(d); normalize(d);
    	point3 c = (p1+p2)/2.0;
    	point3 Y(0,1,0);
    	point3 rd = d^Y; normalize(rd); double ra = -acos(d*Y);
    	double r = (r1+r2)/2;
    	
    	fprintf(fo,
    		"Separator{\n"
    		"\tTranslation { translation %g %g %g }\n"
    		"\t\tRotation { rotation %g %g %g %g }\n"
    		"\t\tCylinder {\n\t\tparts SIDES\n"
            "\t\tradius %g\n\t\theight %g\n"
    		"\t}\n}\n"
    		,c.x*S,c.y*S,c.z*S
    		,rd.x,rd.y,rd.z,ra
    		,r*S,l*S
    	);
    }
    
    void rotate( point4 & p ) {
    	double theta = PI/2; double cs = cos(theta); double sn = sin(theta);
    	double z = p.y;
    	double v = p.v;
    	p.y = z * cs - v * sn;
    	p.v = z * sn + v * cs;
    }
    
    void proj( const point4 & v, point3 & w, double & R ) {
    	w.x = v.x / (2-v.v); w.y = v.y / (2-v.v);
    	w.z = v.z / (2-v.v); R = 1.0 / (2-v.v);
    }
    
    int main() {
    	const int P = 6;
    	const int Q = 4;
    	int i,j;
    	
    	const int NV = P*Q; point4 V[NV];
    	for(i=0;i<P;++i) {
    		double ai = i*2*PI/P;
    		for(j=0;j<Q;++j) {
    			double aj = j*2*PI/Q;
    			V[i*Q+j].x = cos(ai); V[i*Q+j].y = sin(ai);
    			V[i*Q+j].z = cos(aj); V[i*Q+j].v = sin(aj);
    		}
    	}
    	
    	const int NV2 = P+Q; point4 V2[NV2];
    	for(i=0;i<P;++i) {
    		double a1 = i*2*PI/P;         double x1 = cos(a1); double y1 = sin(a1);
    		double a2 = ((i+1)%P)*2*PI/P; double x2 = cos(a2); double y2 = sin(a2);
    		V2[i+0].x = (x1+x2)/2; V2[i+0].z = 0;
    		V2[i+0].y = (y1+y2)/2; V2[i+0].v = 0;
    	}
    	for(j=0;j<Q;++j) {
    		double a1 = j*2*PI/Q;         double z1 = cos(a1); double v1 = sin(a1);
    		double a2 = ((j+1)%Q)*2*PI/Q; double z2 = cos(a2); double v2 = sin(a2);
    		V2[j+P].x = 0; V2[j+P].z = (z1+z2)/2;
    		V2[j+P].y = 0; V2[j+P].v = (v1+v2)/2;
    	}
    	
    	point3 VP[NV]; double R[NV];
    	point3 VP2[NV2]; double R2[NV2];
    	for(i=0;i<NV;++i) {
    		rotate(V[i]); proj(V[i],VP[i],R[i]);
    	}
    	for(i=0;i<NV2;++i) {
    		rotate(V2[i]); proj(V2[i],VP2[i],R2[i]);
    	}
    
    	FILE * fo = fopen("duppyramid.wrl","w");	
    	fprintf(fo, "#VRML V1.0 ascii\n" );
    	
    	fprintf(fo,
    		"Material {\n"
            "\tdiffuseColor [0.4 0.1 0.0]\n"
            "\tspecularColor [0.7 0.7 0.7]\n"
            "\temissiveColor[]\n"
            "\tambientColor[0.4 0.4 0.4]\n"
            "\tshininess 0.16\n"
            "\ttransparency 0.5\n"
    		"}\n"
    	);
     
    	for(i=0;i<NV;++i)
    		draw_sphere(fo,VP[i],R[i]*K2);
    	for(j=0;j<Q;++j)
    		for(i=0;i<P;++i) {
    			draw_edge(fo,VP[i*Q+j],R[i*Q+j]*K1,VP[((i+1)%P)*Q+j],R[((i+1)%P)*Q+j]*K1);
    			draw_edge(fo,VP[i*Q+j],R[i*Q+j]*K1,VP[i*Q+(j+1)%Q],R[i*Q+(j+1)%Q]*K1);
    		}
    
    	fprintf(fo,
    		"Material {\n"
            "\tdiffuseColor [0.1 0.2 0.5]\n"
            "\tspecularColor [0.7 0.7 0.7]\n"
            "\temissiveColor[]\n"
            "\tambientColor[0.4 0.4 0.4]\n"
            "\tshininess 0.16\n"
            "\ttransparency 0.0\n"
    		"}\n"
    	);
     
    	for(i=0;i<NV2;++i)
    		draw_sphere(fo,VP2[i],R2[i]*K2);
    
    	for(i=0;i<P;++i)
    		draw_edge(fo,VP2[i],R2[i]*K1,VP2[(i+1)%P],R2[(i+1)%P]*K1);
    	for(j=0;j<Q;++j)
    		draw_edge(fo,VP2[P+j],R2[P+j]*K1,VP2[P+(j+1)%Q],R2[P+(j+1)%Q]*K1);
    	for(i=0;i<P;++i)
    	for(j=0;j<Q;++j)
    		draw_edge(fo,VP2[0+i],R2[0+i]*K1,VP2[P+j],R2[P+j]*K1);
    
    	fclose(fo);
    	
    	return 0;
    }
    

    Captions

    Add a one-line explanation of what this file represents

    Items portrayed in this file

    depicts

    14 December 2012

    995,180 byte

    1,360 pixel

    1,000 pixel

    image/png

    c564fe938bc4c7f494751bde4e6fb8e7809798f8

    File history

    Click on a date/time to view the file as it appeared at that time.

    Date/TimeThumbnailDimensionsUserComment
    current15:54, 14 December 2012Thumbnail for version as of 15:54, 14 December 20121,000 × 1,360 (972 KB)wikimediacommons>RocchiniUser created page with UploadWizard

    There are no pages that use this file.