wireframe_sphere.py revision cc3e0abe5fb9b8f14bc8f7159d0c5a214f46bc72
0N/A# -*- coding: UTF-8 -*- 0N/ACopyright (C) 2009 John Beard john.j.beard@gmail.com 0N/A######DESCRIPTION###### 0N/AThis extension renders a wireframe sphere constructed from lines of latitude 0N/Aand lines of longitude. 0N/AThe number of lines of latitude and longitude is independently variable. Lines 0N/Aof latitude and longtude are in separate subgroups. The whole figure is also in 0N/AThe whole sphere can be tilted towards or away from the veiwer by a given 0N/Anumber of degrees. If the whole sphere is then rotated normally in Inkscape, 0N/Aany position can be acheived. 5778N/AThere is an option to hide the lines at the back of the sphere, as if the 0N/A #FIXME: Lines of latitude only have an approximation of the function needed 0N/A to hide the back portion. If you can derive the proper equation, 5777N/A Line of longitude have the exact method already. 5777N/A Workaround: Use the Inkscape ellipse tool to edit the start and end 5777N/A points of the lines of latitude to end at the horizon circle. 0N/A#TODO: Add support for odd numbers of lines of longitude. This means breaking 0N/A the line at the poles, and having two half ellipses for each line. 0N/A The angles at which the ellipse arcs pass the poles are not constant and 0N/A need to be derived before this can be implemented. 0N/A#TODO: Add support for prolate and oblate spheroids 0N/AThis program is free software; you can redistribute it and/or modify 0N/Ait under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ######VERSION HISTORY##### 0.10 2009-10-25 First version. Basic spheres supported. Hidden lines of latitude still not properly calculated. Prolate and oblate spheroids not considered. #SVG OUTPUT FUNCTIONS ================================================ style = {
'stroke' :
'#000000',
inkex.
addNS(
'open',
'sodipodi') :
'true',
#all ellipse sectors we will draw are open if so.
NUM_LONG %
2 !=
0:
#lines of longitude are odd : abort inkex.
errormsg(_(
'Please enter an even number of lines of longitude.'))
if so.
TILT <
0:
# if the tilt is backwards flip =
' scale(1, -1)' # apply a vertical flip to the whole sphere EPSILON =
0.001 #add a tiny value to the ellipse radii, so that if we get a zero radius, the ellipse still shows up as a line #INKSCAPE GROUP TO CONTAIN EVERYTHING if so.
NUM_LONG >
0:
#only process longitudes if we actually want some #GROUP FOR THE LINES OF LONGITUDE # length = sqrt(width*width+height*height) #by pythagorean theorem #calculate the rotation of the ellipse to get it to pass through the pole (in degrees) #the rotation will be applied about the group centre (the centre of the sphere) # remove the hidden side of the ellipses if required # this is always exactly half the ellipse, but we need to find out which half start_end = (
0,
2*
pi)
#Default start and end angles -> full ellipse if long_angle <=
pi/
2:
#cut out the half ellispse that is hidden #finally, draw the line of longitude #the centre is always at the centre of the sphere #GROUP FOR THE LINES OF LATITUDE delta_lat =
180.0/
so.
NUM_LAT #Angle between the line of latitude (subtended at the centre) cx=
0 #The x position is just the center of the sphere else:
#this LoLat is partially visible else:
#just draw the full lines of latitude # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99