Skip to content

Commit

Permalink
Using fuzzy comparison for half circle detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert authored and yorikvanhavre committed Mar 3, 2017
1 parent 450e3d8 commit ad8cc9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/Mod/Path/PathScripts/PathGeom.py
Expand Up @@ -26,11 +26,14 @@
import math
import Part
import Path
import PathScripts.PathLog as PathLog

from FreeCAD import Vector

PathGeomTolerance = 0.000001

#PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())

class Side:
"""Class to determine and define the side a Path is on, or Vectors are in relation to each other."""
Left = +1
Expand Down Expand Up @@ -222,21 +225,24 @@ def edgeForCmd(cls, cmd, startPoint):
B = cls.xy(endPoint - center)
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
angle = cls.getAngle(A) + math.pi/2
if cmd.Name in cls.CmdMoveCW:
angle -= math.pi
else:
C = A + B
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
#print("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))
#print("arc: R=%.2f angle=%.2f" % (R, angle/math.pi))
if startPoint.z == endPoint.z:
PathLog.debug("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: A=(%.2f, %.2f) B=(%.2f, %.2f) -> d=%.2f" % (A.x, A.y, B.x, B.y, d))
PathLog.debug("arc: R=%.2f angle=%.2f" % (R, angle/math.pi))
if cls.isRoughly(startPoint.z, endPoint.z):
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))

# It's a Helix
Expand Down
5 changes: 4 additions & 1 deletion src/Mod/Path/PathScripts/PathLog.py
Expand Up @@ -77,6 +77,10 @@ def getLevel(module = None):
return _moduleLogLevel.get(module, _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():
"""internal function to determine the calling module."""
file, line, func, text = traceback.extract_stack(limit=3)[0]
Expand Down Expand Up @@ -161,4 +165,3 @@ def track(*args):
return message
return None


0 comments on commit ad8cc9b

Please sign in to comment.