# -*- coding: UTF-8 -*-
'''
Copyright (C) 2009 John Beard john.j.beard@gmail.com
######DESCRIPTION######
This extension renders a wireframe sphere constructed from lines of latitude
and lines of longitude.
The number of lines of latitude and longitude is independently variable. Lines
of latitude and longtude are in separate subgroups. The whole figure is also in
its own group.
The whole sphere can be tilted towards or away from the veiwer by a given
number of degrees. If the whole sphere is then rotated normally in Inkscape,
any position can be acheived.
There is an option to hide the lines at the back of the sphere, as if the
sphere were opaque.
#FIXME: Lines of latitude only have an approximation of the function needed
to hide the back portion. If you can derive the proper equation,
please add it in.
Line of longitude have the exact method already.
Workaround: Use the Inkscape ellipse tool to edit the start and end
points of the lines of latitude to end at the horizon circle.
#TODO: Add support for odd numbers of lines of longitude. This means breaking
the line at the poles, and having two half ellipses for each line.
The angles at which the ellipse arcs pass the poles are not constant and
need to be derived before this can be implemented.
#TODO: Add support for prolate and oblate spheroids
######LICENCE#######
it 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
######VERSION HISTORY#####
Ver. Date Notes
0.10 2009-10-25 First version. Basic spheres supported.
Hidden lines of latitude still not properly calculated.
Prolate and oblate spheroids not considered.
'''
# standard library
from math import *
# local library
import inkex
import simplestyle
#SVG OUTPUT FUNCTIONS ================================================
'fill' : 'none' }
'transform' :transform
}
#PARSE OPTIONS
#PARAMETER PROCESSING
else:
else:
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
centre = tuple(computePointInNode(list(self.view_center), self.current_layer)) #Put in in the centre of the current view
grp_name = 'WireframeSphere'
'transform':grp_transform }
#LINES OF LONGITUDE
#GROUP FOR THE LINES OF LONGITUDE
grp_name = 'Lines of Longitude'
long_angle = so.ROT_OFFSET + (i*delta_long)*(pi/180.0); #The longitude of this particular line in radians
if long_angle > pi:
# 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
else:
#finally, draw the line of longitude
#the centre is always at the centre of the sphere
# LINES OF LATITUDE
#GROUP FOR THE LINES OF LATITUDE
grp_name = 'Lines of Latitude'
else: #this LoLat is partially visible
start_end = ( pi/2 - proportion*pi, pi/2 + proportion*pi ) #make the start and end angles (mirror image around pi/2)
else: #just draw the full lines of latitude
#THE HORIZON CIRCLE
draw_SVG_ellipse((so.RADIUS, so.RADIUS), (0,0), stroke_width, grp) #circle, centred on the sphere centre
if __name__ == '__main__':
e = Wireframe_Sphere()
e.affect()
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99