Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-07-06 12:36:04 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-07-06 12:36:04 +0400
commit963367750778c4f7c257e94a1e3c5bf192bfa947 (patch)
tree496736f048c64680236ad3cfcaf2a640223c17e2 /modules
parent468578b1801705c48ea366054c2be7fe943f492f (diff)
replace logic in spline intersection which depends on 2D side-of function
Diffstat (limited to 'modules')
-rw-r--r--modules/curve_utils.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/modules/curve_utils.py b/modules/curve_utils.py
index 5fb3c3d4..ce742862 100644
--- a/modules/curve_utils.py
+++ b/modules/curve_utils.py
@@ -20,11 +20,6 @@
import bpy
-def line_point_side_v2(l1, l2, pt):
- return (((l1[0] - pt[0]) * (l2[1] - pt[1])) -
- ((l2[0] - pt[0]) * (l1[1] - pt[1])))
-
-
def vis_curve_object():
scene = bpy.data.scenes[0] # weak!
cu = bpy.data.curves.new(name="Line", type='CURVE')
@@ -370,24 +365,32 @@ def points_to_bezier(points_orig,
# raise Exception("END")
def intersect_line(self, l1, l2, reverse=False):
+ """ Spectial kind of intersection, works in 3d on the plane
+ defimed by the points normal and the line.
+ """
from mathutils.geometry import (intersect_point_line,
)
if reverse:
- p_first = self.points[-2]
+ p_first = self.points[-1]
+ no = -self.points[-1].no
point_iter = reversed(self.points[:-1])
else:
- p_first = self.points[1]
+ p_first = self.points[0]
+ no = self.points[0].no
point_iter = self.points[1:]
- side = (line_point_side_v2(l1, l2, p_first.co) < 0.0)
- ok = False
+ # calculate the line right angles to the line
+ bi_no = (no - no.project(l2 - l1)).normalized()
+
+ bi_l1 = p_first.co
+ bi_l2 = p_first.co + bi_no
+
for p_apex in point_iter:
- if (line_point_side_v2(l1,
- l2,
- p_apex.co,
- ) < 0.0) != side:
+ ix, fac = intersect_point_line(p_apex.co, bi_l1, bi_l2)
+
+ if fac < 0.0001:
if reverse:
p_apex_other = p_apex.next
@@ -407,12 +410,12 @@ def points_to_bezier(points_orig,
w2 = (p_test_2 - p_apex_other.co).length
#assert(w1 + w2 != 0)
- #try:
- fac = w1 / (w1 + w2)
- #except ZeroDivisionError:
- # fac = 0.5
+ try:
+ fac = w1 / (w1 + w2)
+ except ZeroDivisionError:
+ fac = 0.5
assert(fac >= 0.0 and fac <= 1.0)
-
+
p_apex_co = p_apex.co.lerp(p_apex_other.co, fac)
p_apex_no = p_apex.no.lerp(p_apex_other.no, fac)
p_apex_no.normalize()