License New BSD license
Lines 56
Keywords
Nodebox (14) primitives (2) python (33) triangle (2)
Included in this Library
Permissions
Owner: Theodore Test
Group Owner: Nodebox Community
Viewable by Everyone
Editable by All Siafoo Users
Hide
Free your code from a slow death on your hard drive Join Siafoo Now or Learn More

Triangle Primitives by Ideambulate Atom Feed 0

In Brief Some Nodebox triangle primitives borrowed (with permission) from Ideambulate on the Nodebox Share site.... more
# 's
 1from utility_geometry import coordinates
2
3def equilateral_triangle(x0,y0,length,draw=True):
4 '''Draws an equilateral triangle.'''
5
6 x1,y1 = coordinates(x0,y0,length,0)
7 x2,y2 = coordinates(x0,y0,length,60)
8 beginpath(x0,y0)
9 lineto(x1,y1)
10 lineto(x2,y2)
11 lineto(x0,y0)
12 p = endpath(draw)
13 return p
14
15def right_triangle(x0,y0,length1,length2,draw=True):
16 '''Draws a right triangle, with the right angle at the origin'''
17
18 x1,y1 = coordinates(x0,y0,length1,0)
19 x2,y2 = coordinates(x0,y0,length2,90)
20 beginpath(x0,y0)
21 lineto(x1,y1)
22 lineto(x2,y2)
23 lineto(x0,y0)
24 p = endpath(draw)
25 return p
26
27def isoscelestriangle(x0,y0,length,angle,draw=True):
28 '''Draws an isosceles triangle defined by the length of the
29 two equal sides and the angle between them.'''
30 a = 180 - 2*angle
31 x1,y1 = coordinates(x0,y0,length,0)
32 x2,y2 = coordinates(x0,y0,length,a)
33 beginpath(x0,y0)
34 lineto(x1,y1)
35 lineto(x2,y2)
36 lineto(x0,y0)
37 p = endpath(draw)
38 return p
39
40def scalenetriangle(x0,y0,length1,length2,angle,draw=True):
41 '''Draws a scalene triange defined by the length of two sides
42 and the angle between them.'''
43 from math import radians, sin, cos,asin,degrees
44
45 a,c,angB = length1,length2,angle
46 b = (a**2+c**2 - 2.0*a*c*cos(radians(angB)))**0.5
47 angA = degrees(asin((a*sin(radians(angB)))/b))
48 angC = degrees(asin((c*sin(radians(angB)))/b))
49
50 x1,y1 = coordinates(x0,y0,a,0)
51 x2,y2 = coordinates(x0,y0,b,angC)
52
53 beginpath(x0,y0)
54 lineto(x1,y1)
55 lineto(x2,y2)
56 lineto(x0,y0)
57 p = endpath(draw)
58 return p

Some Nodebox triangle primitives borrowed (with permission) from Ideambulate on the Nodebox Share site.

http://www.siafoo.net/image/92