[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [835] branches/ivygen/ivy_functions.py: - another stab at adhesion

Florian Meyer florianfelix at web.de
Thu Jul 22 07:41:40 CEST 2010


Revision: 835
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=835
Author:   testscreenings
Date:     2010-07-22 07:41:38 +0200 (Thu, 22 Jul 2010)

Log Message:
-----------
- another stab at adhesion

Modified Paths:
--------------
    branches/ivygen/ivy_functions.py

Modified: branches/ivygen/ivy_functions.py
===================================================================
--- branches/ivygen/ivy_functions.py	2010-07-22 02:52:46 UTC (rev 834)
+++ branches/ivygen/ivy_functions.py	2010-07-22 05:41:38 UTC (rev 835)
@@ -1,8 +1,5 @@
-def printsomething(): #just abs test if it works
-    print("something")
+
     
-    
-    
 def computeCollision(obj, old_pos, new_pos, tmpRoot):
     '''basic steps:
         thought: maybe implement and octree for the faces
@@ -159,39 +156,74 @@
 ######### i think this should work ##############################################
 ######### retrieving the face and distance to the nearest face of a mesh ########
 #################################################################################
+import bpy
+import mathutils
+import math
 
+# testet this, doesn' do anything meaningful
+# just forget it
 def distance(old_pos, ob):
     distances = {}
-    for i, face in enumerate(obj.data.faces):
+    for i, face in enumerate(ob.data.faces):
 
-        referencePoint = ob.data.verts[face.verts[0]]   # Q
-        normal = face,normal                            # n
+        referencePoint = ob.data.verts[face.verts[0]].co# * ob.matrix_world
+        print('referencePoint', referencePoint)
+        print('old_pos', old_pos)
+        normal = face.normal                            # n
         referenceVector = old_pos - referencePoint      # vector n
+        distance = referenceVector.dot(normal)
+        distance2 = normal.dot(referenceVector)
+        print(distance)
+        print(distance2)
 
-        distance = referenceVector.dot(n)
-        distances[distance] = i
 
-    distance, index = sortDict(distances)
-
-    return distance, index
-
-def sortDict(dict):
-    keys = dict.keys()
-    keys.sort()
-    distance = keys[0][0]   # should maybe run this
-    index = keys[0][1]      # if this data retrieval really works
-    return distance, index
         
         
 ##################################################################################
+def altitude(point1, point2, pointn):
+    edge1 = point2 - point1
+    edge2 = pointn - point1
+    if edge2.length == 0:
+        altitude = 0
+        return altitude
+    if edge1.length == 0:
+        altitude = edge2.length
+        return altitude
+    alpha = edge1.angle(edge2)
+    altitude = math.sin(alpha) * edge2.length
+    return altitude
+
+
+def distance2(old_pos, ob):
+    #print('cursor', old_pos)
+
+    for i, face in enumerate(ob.data.faces):
+        n = face.normal
+        c = face.center + ob.location
+
+        plane_dist = (n.dot(old_pos) +
+                      ( -n.x*c.x -
+                        -n.y*c.y -
+                        -n.z*c  .z))
+        print('plane_dist', plane_dist)
+    # up to here this works
+    # plane_dist is the distance to the plane defined by the face.center and face.normal
+        pointOnPlane = old_pos - n * plane_dist
+        print('pointOnPlane', pointOnPlane)
+        # now find the closest distance to the poly
+        # test if pointOnPlane is already inside the poligon
+        # else get closest point on the closest edge
+'''        
+print('\n______________')
+cur = bpy.context.scene.cursor_location
+#print('cur', cur)
+ob = bpy.context.active_object
+
+distance2(cur, ob)
+'''        
         
         
         
-        
-        
-        
-        
-        
 def register():
     pass
     




More information about the Bf-extensions-cvs mailing list