[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [841] branches/ivygen/ivy_functions.py: - added 2 functions to test if a point is inside a polygon
Florian Meyer
florianfelix at web.de
Thu Jul 22 13:09:27 CEST 2010
Revision: 841
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=841
Author: testscreenings
Date: 2010-07-22 13:09:26 +0200 (Thu, 22 Jul 2010)
Log Message:
-----------
- added 2 functions to test if a point is inside a polygon
Modified Paths:
--------------
branches/ivygen/ivy_functions.py
Modified: branches/ivygen/ivy_functions.py
===================================================================
--- branches/ivygen/ivy_functions.py 2010-07-22 08:24:04 UTC (rev 840)
+++ branches/ivygen/ivy_functions.py 2010-07-22 11:09:26 UTC (rev 841)
@@ -193,7 +193,46 @@
altitude = math.sin(alpha) * edge2.length
return altitude
+def testangles(ob, face, point):
+ #this may be known as the worst algorithm for this problem.
+ #returns the added angles between th point and the faces verts
+ #the closer this value is to 2PI the more likely the point is on the inside
+ #of the polygon. This may not be that reliable because quadPolys
+ #may not be coplanar, and the anglevalue drops below 2PI (6.2831).
+
+ angle = 0
+ verts = [ob.data.verts[i] for vert, i in enumerate(face.verts)]
+ for i, vert in enumerate(verts):
+ angle += (point - verts[i].co).angle(point - verts[i-1].co, 0)
+
+ return angle
+
+def isInside(ob, face, point):
+ #tests if the point is always on the same side of the edges
+ #seems to work reasonably well, except:
+ #returns False if the point lies directly on a vert
+
+ inside = False
+ bigger = 0
+ smaller = 0
+ for edge in face.edge_keys:
+ v1 = ob.data.verts[edge[0]]
+ v2 = ob.data.verts[edge[1]]
+ val = (v1.co - v2.co).cross(point - v1.co)
+ com = (v1.co - v2.co).cross(point - ob.data.verts[edge[0]-2].co)
+ prod = val.dot(com)
+ if prod >= 0:
+ bigger += 1
+ else:
+ smaller += 1
+
+ if bigger == 0 or smaller == 0:
+ return True
+ else:
+ return False
+
+ return value
def distance2(old_pos, ob):
#print('cursor', old_pos)
More information about the Bf-extensions-cvs
mailing list