[frames] | no frames]

# Source Code for Module Geometry

```  1  # Blender.Geometry module and its subtypes
2
3  """
4  The Blender.Geometry submodule.
5
6  Geometry
7  ========
8
10  """
11
12 -def PolyFill(polylines):
13          """
14          Takes a list of polylines and calculates triangles that would fill in the polylines.
15          Multiple lines can be used to make holes inside a polyline, or fill in 2 seperate lines at once.
16          @type polylines: List of lists containing vectors, each representing a closed polyline.
17          @rtype: list
18          @return: a list if tuples each a tuple of 3 ints representing a triangle indexing the points given.
19          @note: 2D Vectors will have an assumed Z axis of zero, 4D Vectors W axis is ignored.
20          @note: The order of points in a polyline effect the direction returned triangles face, reverse the order of a polyline to flip the normal of returned faces.
21
22          I{B{Example:}}
23
24          The example below creates 2 polylines and fills them in with faces, then makes a mesh in the current scene::
25                  import Blender
26                  Vector= Blender.Mathutils.Vector
27
28                  # Outline of 5 points
29                  polyline1= [Vector(-2.0, 1.0, 1.0), Vector(-1.0, 2.0, 1.0), Vector(1.0, 2.0, 1.0), Vector(1.0, -1.0, 1.0), Vector(-1.0, -1.0, 1.0)]
30                  polyline2= [Vector(-1, 1, 1.0), Vector(0, 1, 1.0), Vector(0, 0, 1.0), Vector(-1.0, 0.0, 1.0)]
31                  fill= Blender.Geometry.PolyFill([polyline1, polyline2])
32
33                  # Make a new mesh and add the truangles into it
34                  me= Blender.Mesh.New()
35                  me.verts.extend(polyline1)
36                  me.verts.extend(polyline2)
37                  me.faces.extend(fill) # Add the faces, they reference the verts in polyline 1 and 2
38
39                  scn = Blender.Scene.GetCurrent()
40                  ob = scn.objects.new(me)
41                  Blender.Redraw()
42          """
43
44 -def LineIntersect2D(vec1, vec2, vec3, vec4):
45          """
46          Takes 2 lines vec1, vec2 for the 2 points of the first line and vec2, vec3 for the 2 points of the second line.
47          @rtype: Vector
48          @return: a 2D Vector for the intersection or None where there is no intersection.
49          """
50
51 -def ClosestPointOnLine(pt, vec1, vec2):
52          """
53          Takes 2 lines vec1, vec2 for the 2 points of the first line and vec2, vec3 for the 2 points of the second line.
54          @rtype: tuple
55          @return: a tuple containing a vector and a float, the vector is the closest point on the line, the float is the position on the line, between 0 and 1 the point is on the line.
56          """
57
58 -def PointInTriangle2D(pt, tri_pt1, tri_pt2, tri_pt3):
59          """
60          Takes 4 vectors (one for the test point and 3 for the triangle)
61          This is a 2d function so only X and Y are used, Z and W will be ignored.
62          @rtype: int
63          @return: 1 for a clockwise intersection, -1 for counter clockwise intersection, 0 when there is no intersection.
64          """
65
67          """
68          Takes 5 vectors (one for the test point and 5 for the quad)
69          This is a 2d function so only X and Y are used, Z and W will be ignored.
70          @rtype: int
71          @return: 1 for a clockwise intersection, -1 for counter clockwise intersection, 0 when there is no intersection.
72          """
73
74 -def BoxPack2D(boxlist):
75          """
76          Takes a list of 2D boxes and packs them into a square.
77          Each box in boxlist must be a list of at least 4 items - [x,y,w,h], after running this script,
78          the X and Y values in each box will be moved to packed, non overlapping locations.
79
80          Example::
81
82                  # Make 500 random boxes, pack them and make a mesh from it
83                  from Blender import Geometry, Scene, Mesh
84                  import random
85                  boxes = []
86                  for i in xrange(500):
87                          boxes.append( [0,0, random.random()+0.1, random.random()+0.1] )
88                  boxsize = Geometry.BoxPack2D(boxes)
89                  print 'BoxSize', boxsize
90                  me = Mesh.New()
91                  for x in boxes:
92                          me.verts.extend([(x[0],x[1], 0), (x[0],x[1]+x[3], 0), (x[0]+x[2],x[1]+x[3], 0), (x[0]+x[2],x[1], 0) ])
93                          v1= me.verts[-1]
94                          v2= me.verts[-2]
95                          v3= me.verts[-3]
96                          v4= me.verts[-4]
97                          me.faces.extend([(v1,v2,v3,v4)])
98                  scn = Scene.GetCurrent()
99                  scn.objects.new(me)
100
101          @note: Each boxlist item can be longer then 4, the extra items are ignored and stay untouched.
102          @rtype: tuple
103          @return: a tuple pair - (width, height) of all the packed boxes.
104          """
105
<!--
expandto(location.href);
// -->

```

 Generated by Epydoc 3.0.1 on Fri Oct 24 10:23:55 2008 http://epydoc.sourceforge.net