parent
e6816fb551
commit
f8dfcd6615
24
utils.py
24
utils.py
|
@ -334,6 +334,7 @@ def getEdgeRotation(edge):
|
||||||
elif hasattr( curve, 'Axis'): #circular curve
|
elif hasattr( curve, 'Axis'): #circular curve
|
||||||
axis = curve.Axis
|
axis = curve.Axis
|
||||||
else:
|
else:
|
||||||
|
axis = None
|
||||||
BSpline = curve.toBSpline()
|
BSpline = curve.toBSpline()
|
||||||
arcs = BSpline.toBiArcs(10**-6)
|
arcs = BSpline.toBiArcs(10**-6)
|
||||||
if all( hasattr(a,'Center') for a in arcs ):
|
if all( hasattr(a,'Center') for a in arcs ):
|
||||||
|
@ -341,14 +342,14 @@ def getEdgeRotation(edge):
|
||||||
sigma = np.std( centers, axis=0 )
|
sigma = np.std( centers, axis=0 )
|
||||||
if max(sigma) < 10**-6: #then circular curce
|
if max(sigma) < 10**-6: #then circular curce
|
||||||
axis = arcs[0].Axis
|
axis = arcs[0].Axis
|
||||||
if all(isLine(a) for a in arcs):
|
elif all(isLine(a) for a in arcs):
|
||||||
lines = arcs
|
lines = arcs
|
||||||
D = np.array(
|
D = np.array(
|
||||||
[L.tangent(0)[0] for L in lines]) #D(irections)
|
[L.tangent(0)[0] for L in lines]) #D(irections)
|
||||||
if np.std( D, axis=0 ).max() < 10**-9: #then linear curve
|
if np.std( D, axis=0 ).max() < 10**-9: #then linear curve
|
||||||
return D[0]
|
axis = FreeCAD.Vector(*D[0])
|
||||||
if not axis:
|
if not axis:
|
||||||
return FreeCAD.Rotation()
|
return edge.Placement.Rotation
|
||||||
return FreeCAD.Rotation(FreeCAD.Vector(0,0,1),axis)
|
return FreeCAD.Rotation(FreeCAD.Vector(0,0,1),axis)
|
||||||
|
|
||||||
def getElementRotation(obj,reverse=False):
|
def getElementRotation(obj,reverse=False):
|
||||||
|
@ -358,6 +359,7 @@ def getElementRotation(obj,reverse=False):
|
||||||
edge = getElementShape(obj,Part.Edge)
|
edge = getElementShape(obj,Part.Edge)
|
||||||
if edge:
|
if edge:
|
||||||
return getEdgeRotation(edge)
|
return getEdgeRotation(edge)
|
||||||
|
return FreeCAD.Rotation()
|
||||||
else:
|
else:
|
||||||
if face.Orientation == 'Reversed':
|
if face.Orientation == 'Reversed':
|
||||||
reverse = not reverse
|
reverse = not reverse
|
||||||
|
@ -378,14 +380,14 @@ def getElementRotation(obj,reverse=False):
|
||||||
error_normalized = error / face.BoundBox.DiagonalLength
|
error_normalized = error / face.BoundBox.DiagonalLength
|
||||||
if error_normalized < 10**-6: #then good plane fit
|
if error_normalized < 10**-6: #then good plane fit
|
||||||
axis = FreeCAD.Vector(plane_norm)
|
axis = FreeCAD.Vector(plane_norm)
|
||||||
axis_fitted, _center, error = \
|
else:
|
||||||
fit_rotation_axis_to_surface1(face.Surface)
|
axis_fitted, _center, error = \
|
||||||
error_normalized = error / face.BoundBox.DiagonalLength
|
fit_rotation_axis_to_surface1(face.Surface)
|
||||||
if error_normalized < 10**-6: #then good rotation_axis fix
|
error_normalized = error / face.BoundBox.DiagonalLength
|
||||||
axis = FreeCAD.Vector(axis_fitted)
|
if error_normalized < 10**-6: #then good rotation_axis fix
|
||||||
|
axis = FreeCAD.Vector(axis_fitted)
|
||||||
if not axis:
|
if not axis:
|
||||||
return FreeCAD.Rotation()
|
return face.Placement.Rotation
|
||||||
return FreeCAD.Rotation(FreeCAD.Vector(0,0,-1 if reverse else 1),axis)
|
return FreeCAD.Rotation(FreeCAD.Vector(0,0,-1 if reverse else 1),axis)
|
||||||
|
|
||||||
def getElementPlacement(obj,mat=None):
|
def getElementPlacement(obj,mat=None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user