draw_from_triangle.py revision e9b6af083e34e2397a8ddbe9781920733d09d151
'''
Copyright (C) 2007 John Beard john.j.beard@gmail.com
##This extension allows you to draw various triangle constructions
##It requires a path to be selected
##It will use the first three nodes of this path
## Dimensions of a triangle__
#
# /`__
# / a_c``--__
# / ``--__ s_a
# s_b / ``--__
# /a_a a_b`--__
# /--------------------------------``B
# A s_b
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
import inkex
from math import *
import gettext
#DRAWING ROUTINES
#draw an SVG triangle given in trilinar coords
def draw_SVG_circle(rad, centre, params, style, name, parent):#draw an SVG circle with a given radius as trilinear coordinates
else:
r = rad #use given value
'r':str(r)}
#draw an SVG triangle given in trilinar coords
#draw an SVG line segment between the given (raw) points
#lines from each vertex to a corresponding point in trilinears
for i in range(3):
#MATHEMATICAL ROUTINES
def get_cartesian_pt( t, p):#get the cartesian coordinates from a trilinear set
def get_cartesian_tri( ((t11,t12,t13),(t21,t22,t23),(t31,t32,t33)), params):#get the cartesian points from a trilinear vertex matrix
def angle_from_3_sides(a, b, c): #return the angle opposite side c
string = string.replace('s_a', 'params[0]['+str((os+0)%3)+']') #replace with ref. to the relvant values,
return string
trilin_pts=[]#will hold the final points
for i in range(3):
return trilin_pts
#SVG DATA PROCESSING
def get_n_points_from_path( node, n):#returns a list of first n points (x,y) in an SVG path-representing node
xi = [] #temporary storage for x and y (will combine at end)
yi = []
points = [] # returned pairs of points
for i in range(n):
else:
#inkex.errormsg(_('Error: Not enough nodes to gather coordinates.')) #fail silently and exit, rather than invoke an error console
return [] #return a blank
return points
#EXTRA MATHS FUNCTIONS
def sec(x):#secant(x)
return 100000000000
else:
return 1/cos(x)
def csc(x):#cosecant(x)
return 100000000000
else:
return 1/sin(x)
def cot(x):#cotangent(x)
return 100000000000
else:
return 1/tan(x)
return
#dot markers
#lines
#circles
help="The selected UI-tab when OK was pressed")
#PRESET POINT OPTIONS
#CUSTOM POINT OPTIONS
pts = [] #initialise in case nothing is selected and following loop is not executed
pts = get_n_points_from_path( node, 3 ) #find the (x,y) coordinates of the first 3 points of the path
#CREATE A GROUP TO HOLD ALL GENERATED ELEMENTS IN
#Hold relative to point A (pt[0])
'transform':group_translation }
#GET METRICS OF THE TRIANGLE
#vertices in the local coordinates (set pt[0] to be the origin)
area = sqrt( semiperim*(semiperim-s_a)*(semiperim-s_b)*(semiperim-s_c) ) #area of the triangle by heron's formula
#BEGIN DRAWING
if so.do_circumcentre:
if so.do_circumcircle:
if so.do_incentre:
if so.do_incircle:
if so.do_contact_tri:
if so.do_extouch_tri:
if so.do_orthocentre:
if so.do_orthic_tri:
if so.do_centroid:
if so.do_ninepointcentre:
if so.do_ninepointcircle:
if so.do_altitudes:
if so.do_anglebisectors:
if so.do_excentral_tri:
for i in range(3):
if so.do_excircles:
if so.do_excentres:
if so.do_sym_tri:
if so.do_symmedians:
if so.do_gergonne_pt:
if so.do_nagel_pt:
pt = []#where we will store the point in trilinears
for i in range(3):
func = eval('lambda params: ' + strings[i].strip('"')) #the function leading to the trilinar element
else:#we need a triangle function
if so.do_isogonal_conj:
for i in range (3):
if so.do_isotomic_conj:
for i in range (3):
e = Draw_From_Triangle()
e.affect()