Esta imagen se puede generar completamente con el siguiente código fuente. Si tiene instalada la colección del compilador GNU, el programa se puede compilar con los siguientes comandos:
Crea el archivo Sphere_wireframe.svg en el directorio de trabajo. Este archivo se puede ver usando el programa rsvg-view:
/ * esfera: crea un archivo svg de gráficos vectoriales que representa una esfera de estructura metálica * * Copyright (C) 2008 Wikimedia foundation * * Este programa es software gratuito; puede redistribuirlo y / o modificarlo * según los términos de la Licencia Pública General GNU publicada por * la Free Software Foundation; ya sea la versión 2, o (a su elección) * cualquier versión posterior. * * Este programa se distribuye con la esperanza de que sea útil, * pero SIN NINGUNA GARANTÍA; incluso sin la garantía implícita de * COMERCIABILIDAD o APTITUD PARA UN PROPÓSITO PARTICULAR. Consulte la Licencia pública general * GNU para obtener más detalles. ** Debería haber recibido una copia de la Licencia Pública General GNU * junto con este programa; si no es así, puede enviar un correo electrónico al autor de este * programa (ver más abajo) o escribir a: * The Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA * // * No se ha demostrado que las expresiones de este código sean correctas. * Por lo tanto, este código probablemente contiene muchos errores. ¡Esté atento! * /#include <iostream>#include <cmath>#include <cstdlib>#include <cstring>usando el espacio de nombres std ;const doble PI = 3,1415926535897932 ; const doble DEG = PI / 180.0 ;/********************************* ajustes *************** ******************* / int n_lon = 18 ; // número de campos de latitud (18 => 10 ° cada uno) int n_lat = 18 ; // la mitad del número de campos de longitud (18 => 10 ° cada uno) double lon_offset = 2.5 * DEG ; // desplazamiento de los meridianos double w = 52.5 * DEG ; // Inclinación axial (0 ° => el eje es perpendicular al plano de la imagen) double stripe_grad = 0.5 * DEG ; // ancho de cada líneaint tamaño_imagen = 400 ; // ancho y alto de la imagen en píxeles double back_opacity = 0.25 ; // opacidad del color char de la parte trasera de la esfera [] = "# 334070" ; // color de las líneas int istep = 2 ; // paso de sangría del código svg / **************************************** ********************************* / doble sqr ( doble x ) { retorno ( x * x ); }// comandos para el código svg: void indent ( int n , bool in_tag = false ) { n * = istep ; if ( in_tag ) n + = istep + 1 ; para ( int i = 0 ; i < n ; i ++ ) cout << "" ; } void M () { cout << "M" ; }void Z () { cout << "Z" ; } void xy ( doble x , doble y ) { cout << x << "," ; cout << y << "" ; } arco vacío ( doble a , doble b , doble x_axis_rot , bool large_arc , bool sweep ) { // dibuja un arco elíptico si ( b < 0.5E-6 ) { // Las elipses planas no se representan correctamente => use la línea cout << "L" ; } else { cout << "A" ; cout << a << "," ; // semi-eje mayor cout << b << "" ; // eje semi-menor cout << x_axis_rot << "" ; cout << arco_grande << "" ;cout << barrer << ""; } } círculo vacío ( bool en el sentido de las agujas del reloj ) { M (); xy ( -1 , 0 ); de arco ( 1 , 1 , 0 , 0 , ! las agujas del reloj ); xy ( 1 , 0 ); de arco ( 1 , 1 , 0 , 0 , ! las agujas del reloj ); xy ( -1 , 0 ); Z (); }void start_svg_file () { cout << "<? xml version = \" 1.0 \ " encoding = \" UTF-8 \ " standalone = \" no \ " ?> \ n " ; cout << "<svg id = \" Sphere_wireframe \ "\ n " ; cout << "versión = \" 1.1 \ "\ n " ; cout << "baseProfile = \" completo \ "\ n "; cout << "xmlns = \"http://www.w3.org/2000/svg \ "\ n " ; cout << "xmlns: xlink = \" http://www.w3.org/1999/xlink \ "\ n " ; cout << "ancho = \" " << tamaño_imagen << " \ "\ n " ; cout << "altura = \" " << tamaño_imagen << " \ " > \ n \ n " ; cout << "<title> Estructura alámbrica de esfera </title>\ n \ n " ; cout << " <desc> \ n" ; cout << " acerca de: http://commons.wikimedia.org/wiki/Image:Sphere_wireframe.svg \ n " ; cout << " derechos: licencia de documentación libre GNU, \ n " ; cout << " Creative Commons Licencia de atribución ShareAlike \ n " ; cout << " </desc> \ n \ n " ; cout << " <g id = \ " esfera \" transform = \ " scale (" << 0.5 * tamaño_imagen ; cout << "," << -0.5 * tamaño_imagen << ") translate (1, -1) \" > \ n " ; }void end_svg_file () { cout << "</g> \ n </svg> \ n " ; }int main ( int argc , char * argv []) { // acepta -lat y -lon como parámetro para ( int i = 2 ; i < argc ; i ++ ) { if ( isdigit ( argv [ i ] [ 0 ] ) || ( tamaño de ( argv [ i ]) > tamaño de ( carácter ) && es un dígito ( argv[ i ] [ 1 ]) && ( argv [ i ] [ 0 ] == '.' || argv [ i ] [ 0 ] == '-' ))) { if ( strcmp ( argv [ i - 1 ], "-lon" ) == 0 ) { lon_offset = atof ( argv [ i ]) * DEG ; } si ( strcmp( argv [ i - 1 ], "-lat" ) == 0 ) { w = atof ( argv [ i ]) * DEG ; } } } doble cosw = cos ( w ), sinw = sin ( w ); doble d = 0.5 * stripe_grad ;start_svg_file (); int ind = 2 ; // nivel de sangría inicial guión ( ind ); cout << "<g id = \" esfera_back \ " transform = \" rotate (180) \ " " ; cout << "opacidad = \" " << back_opacity << " \ " > \ n " ; sangría ( ++ ind ); cout << "<g id = \"media_esfera \ " >\ n " ;// sangría de meridianos ( ++ ind ); cout << "<g id = \" meridianos \ "\ n " ; sangría ( ind ++ , verdadero ); cout << "estilo = \" trazo: ninguno; relleno: " << color << "; fill_rule: evenodd \ " > \ n " ; doble a = abs ( cos ( d )); para ( int i_lon = 0 ; i_lon < n_lat ; i_lon ++ ) { // dibujar un meridiano doble longitud = lon_offset + ( i_lon * 180,0 / n_lat ) * DEG ; doble lon [ 2 ]; lon [ 0 ] = longitud + d ; lon [ 1 ] = longitud - d ;sangría ( ind ); cout << "<ruta id = \" meridiano " ; cout << i_lon << " \ "\ n " ; sangría ( ind , verdadero ); cout << "d = \" " ;double axis_rot = atan2 ( -1.0 / tan ( longitud ), cosw ); si ( senw < 0 ) eje_rot + = PI ; doble w2 = sin ( longitud ) * sinw ; doble b = abs ( w2 * cos ( d ));doble sinw1 = sin ( d ) / sqrt ( 1.0 - sqr ( sin ( longitud ) * sinw ));if ( abs ( sinw1 ) > = 1.0 ) { // la raya cubre el borde del círculo double w3 = sqrt ( 1.0 - sqr ( w2 )) * sin ( d ); círculo ( falso ); // elipse M (); xy ( sin ( eje_rot ) * w3 - cos ( eje_rot ) * a , - cos (eje_rot ) * w3 - sin ( eje_rot ) * a ); arco ( a , b , eje_rot / DEG , 0 , 0 ); xy ( sin ( eje_rot ) * w3 + cos ( eje_rot ) * a , - cos ( eje_rot ) * w3 + sin ( eje_rot ) * a); arco ( a , b , eje_rot / DEG , 0 , 0 ); xy ( sin ( eje_rot ) * w3 - cos ( eje_rot ) * a , - cos ( eje_rot ) * w3 - sin ( eje_rot ) * a ); Z (); } else { // dibuja un arco de elipse interrumpido doble w1 = asin ( sinw1 ); M (); xy ( - cos ( eje_rot + w1 ), - sin ( eje_rot + w1 )); arco ( a , b , eje_rot / DEG , 1 , 0 ); xy ( cos ( eje_rot - w1 ), sin ( eje_rot - w1 )); arco ( 1 , 1, 0 , 0 , 1 ); xy ( cos ( eje_rot + w1 ), sin ( eje_rot + w1 )); arco ( a , b , eje_rot / DEG , 0 , 1 ); xy ( - cos ( eje_rot - w1 ), - sin ( eje_rot - w1 )); arco ( 1 , 1, 0 , 0 , 1 ); xy ( - cos ( eje_rot + w1 ), - sin ( eje_rot + w1 )); } Z (); cout << " \" /> \ n " ; } sangría ( - ind ); cout << " </g> \ n " ;cout << endl ;// círculos de latitud sangría ( ind ); cout << "<g id = \" círculos_de_latitud \ "\ n " ; sangría ( ind , verdadero ); cout << "estilo = \" trazo: ninguno; relleno: " << color << "; fill_rule: evenodd \ " > \ n " ; ind ++ ; para ( int i_lat = 1 ; i_lat < n_lon ; i_lat ++ ){ // dibujar un paralelo doble latitud = ( i_lat * 180,0 / n_lon - 90,0 ) * DEG ; latitud doble [ 2 ]; lat [ 0 ] = latitud + d ; lat [ 1 ] = latitud - d ; doble x [ 2 ], yd [ 2 ], ym [ 2 ]; por ( int i = 0 ; i < 2 ; i ++ ) { x [ i ] = abs ( cos ( lat [ i ])); yd [ i ] = abs ( cosw * cos ( lat [ i ])); ym [ i ] = sinw * sin ( lat [ i ]); } doble h[ 4 ]; // altura de cada punto sobre el plano de la imagen h [ 0 ] = sin ( lat [ 0 ] + w ); h [ 1 ] = sen ( lat [ 0 ] - w ); h [ 2 ] = sen ( lat [ 1 ] + w ); h [ 3 ] = sin ( lat [ 1 ] - w );if ( h [ 0 ] > 0 || h [ 1 ] > 0 || h [ 2 ] > 0 || h [ 3 ] > 0 ) { // al menos cualquier parte visible sangría ( ind ); cout << "<ruta id = \" círculo_de_latitud " ; cout << i_lat << " \ "\ n " ; sangría ( ind , cierto ); cout << "d = \" " ; for ( int i = 0 ; i < 2 ; i ++ ) { if (( h [ 2 * i ] > = 0 && h [ 2 * i + 1 ] > = 0 ) && ( h [ 2 * i ] > 0 || h [ 2* i + 1 ] > 0 )) { // completa elipse M (); xy ( - x [ i ], ym [ i ]); // punto de inicio para ( int z = 1 ; z > -2 ; z - = 2 ) { arc ( x [ i ], yd [ i ], 0 , 1 , i ); xy( z * x [ i ], ym [ i ]); } Z (); if ( h [ 2-2 * i ] * h [ 3-2 * i ] < 0 ) { // parcialmente elipse + parcialmente círculo doble yp = sin ( lat [ 1 - i ]) / sinw ; doble xp = sqrt ( 1.0 - sqr( yp )); si ( senw < 0 ) { xp = - xp ; } M (); xy ( - xp , yp ); arco ( x [ 1 - i ], yd [ 1 - i ], 0 , sen ( lat [ 1 - i ]) * cosw > 0 , cosw > = 0 ); xy( xp , yp ); arco ( 1 , 1 , 0 , 0 , cosw > = 0 ); xy ( - xp , yp ); Z (); } más si ( h [ 2-2 * i ] <= 0 && h [ 3-2 * i ] <= 0 ) { // la raya cubre el borde del círculo círculo ( cosw < 0 ); } } }si (( h [ 0 ] * h [ 1 ] < 0 && h [ 2 ] <= 0 && h [ 3 ] <= 0 ) || ( h [ 0 ] <= 0 && h [ 1 ] <= 0 && h [ 2 ] * h [ 3 ] < 0 )) { // un segmento visible int i = h [ 0 ] <= 0 && h [ 1 ] <= 0 ; doble yp = sin ( lat [ i ]) / sinw ; doble xp = sqrt ( 1.0 - yp * yp ); M (); xy ( - xp , yp ); arco ( x [ i ], yd [ i ], 0 , sin ( lat [ i ]) * cosw > 0 , cosw * sinw > = 0 ); xy ( xp , yp ); arco ( 1 , 1 , 0 , 0 , cosw * sinw < 0 ); xy ( - xp , yp ); Z (); } más si ( h [ 0 ] * h [ 1 ] < 0 && h [ 2 ] * h [ 3 ] < 0 ) { // arco de elipse interrumpido doble xp [ 2 ], yp [ 2 ]; para ( int i = 0 ; i < 2 ; i ++ ) { yp [ i ] = sin ( lat [ i ]) / sinw ; xp [ i ] = sqrt ( 1.0 - sqr ( yp [ i ])); si ( senw < 0 ) xp [ i ] = - xp [ i ]; } M (); xy ( - xp [ 0 ], yp [ 0 ]); arco ( x [ 0 ], yd [ 0 ], 0, sin ( lat [ 0 ]) * cosw > 0 , cosw > = 0 ); xy ( xp [ 0 ], yp [ 0 ]); arco ( 1 , 1 , 0 , 0 , 0 ); xy ( xp [ 1 ], yp [ 1 ]); arco ( x [ 1 ], yd [ 1 ], 0, sin ( lat [ 1 ]) * cosw > 0 , cosw < 0 ); xy ( - xp [ 1 ], yp [ 1 ]); arco ( 1 , 1 , 0 , 0 , 0 ); xy ( - xp [ 0 ], yp [ 0 ]); Z (); } cout << " \" />\ n " ; } } for ( int i = 0 ; i < 3 ; i ++ ) { sangría ( - ind ); cout << " </g> \ n " ; } sangría ( ind - ); cout << "<use id = \" spiral_front \ " xlink: href = \" #sphere_half \ " /> \ n " ; end_svg_file ();}