Using fuzzy comparison for half circle detection.
This commit is contained in:
parent
450e3d8383
commit
ad8cc9b07b
|
@ -26,11 +26,14 @@ import FreeCAD
|
||||||
import math
|
import math
|
||||||
import Part
|
import Part
|
||||||
import Path
|
import Path
|
||||||
|
import PathScripts.PathLog as PathLog
|
||||||
|
|
||||||
from FreeCAD import Vector
|
from FreeCAD import Vector
|
||||||
|
|
||||||
PathGeomTolerance = 0.000001
|
PathGeomTolerance = 0.000001
|
||||||
|
|
||||||
|
#PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
|
||||||
|
|
||||||
class Side:
|
class Side:
|
||||||
"""Class to determine and define the side a Path is on, or Vectors are in relation to each other."""
|
"""Class to determine and define the side a Path is on, or Vectors are in relation to each other."""
|
||||||
Left = +1
|
Left = +1
|
||||||
|
@ -222,7 +225,8 @@ class PathGeom:
|
||||||
B = cls.xy(endPoint - center)
|
B = cls.xy(endPoint - center)
|
||||||
d = -B.x * A.y + B.y * A.x
|
d = -B.x * A.y + B.y * A.x
|
||||||
|
|
||||||
if d == 0:
|
if cls.isRoughly(d, 0, 0.005):
|
||||||
|
PathLog.info("Half circle arc at: (%.2f, %.2f, %.2f)" % (center.x, center.y, center.z))
|
||||||
# we're dealing with half a circle here
|
# we're dealing with half a circle here
|
||||||
angle = cls.getAngle(A) + math.pi/2
|
angle = cls.getAngle(A) + math.pi/2
|
||||||
if cmd.Name in cls.CmdMoveCW:
|
if cmd.Name in cls.CmdMoveCW:
|
||||||
|
@ -230,13 +234,15 @@ class PathGeom:
|
||||||
else:
|
else:
|
||||||
C = A + B
|
C = A + B
|
||||||
angle = cls.getAngle(C)
|
angle = cls.getAngle(C)
|
||||||
|
PathLog.info("Arc (%8f) at: (%.2f, %.2f, %.2f) -> angle=%f" % (d, center.x, center.y, center.z, angle / math.pi))
|
||||||
|
|
||||||
R = A.Length
|
R = A.Length
|
||||||
#print("arc: p1=(%.2f, %.2f) p2=(%.2f, %.2f) -> center=(%.2f, %.2f)" % (startPoint.x, startPoint.y, endPoint.x, endPoint.y, center.x, center.y))
|
PathLog.debug("arc: p1=(%.2f, %.2f) p2=(%.2f, %.2f) -> center=(%.2f, %.2f)" % (startPoint.x, startPoint.y, endPoint.x, endPoint.y, center.x, center.y))
|
||||||
#print("arc: A=(%.2f, %.2f) B=(%.2f, %.2f) -> d=%.2f" % (A.x, A.y, B.x, B.y, d))
|
PathLog.debug("arc: A=(%.2f, %.2f) B=(%.2f, %.2f) -> d=%.2f" % (A.x, A.y, B.x, B.y, d))
|
||||||
#print("arc: R=%.2f angle=%.2f" % (R, angle/math.pi))
|
PathLog.debug("arc: R=%.2f angle=%.2f" % (R, angle/math.pi))
|
||||||
if startPoint.z == endPoint.z:
|
if cls.isRoughly(startPoint.z, endPoint.z):
|
||||||
midPoint = center + Vector(math.cos(angle), math.sin(angle), 0) * R
|
midPoint = center + Vector(math.cos(angle), math.sin(angle), 0) * R
|
||||||
|
PathLog.debug("arc: (%.2f, %.2f) -> (%.2f, %.2f) -> (%.2f, %.2f)" % (startPoint.x, startPoint.y, midPoint.x, midPoint.y, endPoint.x, endPoint.y))
|
||||||
return Part.Edge(Part.Arc(startPoint, midPoint, endPoint))
|
return Part.Edge(Part.Arc(startPoint, midPoint, endPoint))
|
||||||
|
|
||||||
# It's a Helix
|
# It's a Helix
|
||||||
|
|
|
@ -77,6 +77,10 @@ def getLevel(module = None):
|
||||||
return _moduleLogLevel.get(module, _defaultLogLevel)
|
return _moduleLogLevel.get(module, _defaultLogLevel)
|
||||||
return _defaultLogLevel
|
return _defaultLogLevel
|
||||||
|
|
||||||
|
def thisModule():
|
||||||
|
"""returns the module id of the caller, can be used for setLevel, getLevel and trackModule."""
|
||||||
|
return _caller()[0]
|
||||||
|
|
||||||
def _caller():
|
def _caller():
|
||||||
"""internal function to determine the calling module."""
|
"""internal function to determine the calling module."""
|
||||||
file, line, func, text = traceback.extract_stack(limit=3)[0]
|
file, line, func, text = traceback.extract_stack(limit=3)[0]
|
||||||
|
@ -161,4 +165,3 @@ def track(*args):
|
||||||
return message
|
return message
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user