Skip to content

Commit

Permalink
Fix zero division errors for Ellipse curve.
Browse files Browse the repository at this point in the history
  • Loading branch information
portnov committed Jun 16, 2021
1 parent f3b5d1e commit ed7c93b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
20 changes: 18 additions & 2 deletions utils/curve/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,26 @@ def second_derivative_array(self, ts):
return vs

def to_nurbs(self, implementation=SvNurbsMaths.NATIVE):
scale = Matrix([[1,0,0], [0, self.b/self.a, 0], [0, 0, 1]]).to_4x4()
if self.a == 0 and self.b == 0:
coef_x = 0
coef_y = 0
radius = 0
elif self.a == 0:
coef_x = 0
coef_y = 1
radius = self.b
elif self.b == 0:
coef_x = 1
coef_y = 0
radius = self.a
else:
coef_x = 1
coef_y = self.b/self.a
radius = self.a
scale = Matrix([[coef_x,0,0], [0, coef_y, 0], [0, 0, 1]]).to_4x4()
matrix = Matrix(self.matrix).to_4x4()
matrix.translation = Vector(self.get_center())
circle = SvCircle(matrix = matrix @ scale, radius = self.a,
circle = SvCircle(matrix = matrix @ scale, radius = radius,
center = self.get_center())
return circle.to_nurbs(implementation)

2 changes: 2 additions & 0 deletions utils/geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,8 @@ def c(self):
"""
a = self.a
b = self.b
if a < b:
raise Exception("Major semi-axis of the ellipse can not be smaller than minor semi-axis")
return sqrt(a*a - b*b)

@property
Expand Down
6 changes: 6 additions & 0 deletions utils/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ def np_normalize_vectors(vecs):
vecs[nonzero] = vecs[nonzero] / norms[nonzero][:,np.newaxis]
return vecs

def np_multiply_matrices_vectors(matrices, vectors):
vectors = vectors[np.newaxis]
vectors = np.transpose(vectors, axes=(1,2,0))
r = matrices @ vectors
return r[:,:,0]

def weighted_center(verts, field=None):
if field is None:
return np.mean(verts, axis=0)
Expand Down

0 comments on commit ed7c93b

Please sign in to comment.