Draft: move functions to draftgeoutils.arcs
This commit is contained in:
@@ -37,6 +37,7 @@ SET (Draft_geoutils
|
||||
draftgeoutils/faces.py
|
||||
draftgeoutils/geometry.py
|
||||
draftgeoutils/wires.py
|
||||
draftgeoutils/arcs.py
|
||||
)
|
||||
|
||||
SET(Draft_tests
|
||||
|
||||
@@ -190,40 +190,13 @@ def mirror(point, edge):
|
||||
return None
|
||||
|
||||
|
||||
def isClockwise(edge, ref=None):
|
||||
"""Return True if a circle-based edge has a clockwise direction."""
|
||||
if not geomType(edge) == "Circle":
|
||||
return True
|
||||
v1 = edge.Curve.tangent(edge.ParameterRange[0])[0]
|
||||
if DraftVecUtils.isNull(v1):
|
||||
return True
|
||||
# we take an arbitrary other point on the edge that has little chances to be aligned with the first one...
|
||||
v2 = edge.Curve.tangent(edge.ParameterRange[0]+0.01)[0]
|
||||
n = edge.Curve.Axis
|
||||
# if that axis points "the wrong way" from the reference, we invert it
|
||||
if not ref:
|
||||
ref = Vector(0,0,1)
|
||||
if n.getAngle(ref) > math.pi/2:
|
||||
n = n.negative()
|
||||
if DraftVecUtils.angle(v1,v2,n) < 0:
|
||||
return False
|
||||
if n.z < 0:
|
||||
return False
|
||||
return True
|
||||
from draftgeoutils.arcs import isClockwise
|
||||
|
||||
|
||||
from draftgeoutils.edges import isSameLine
|
||||
|
||||
|
||||
def isWideAngle(edge):
|
||||
"""returns True if the given edge is an arc with angle > 180 degrees"""
|
||||
if geomType(edge) != "Circle":
|
||||
return False
|
||||
r = edge.Curve.Radius
|
||||
total = 2*r*math.pi
|
||||
if edge.Length > total/2:
|
||||
return True
|
||||
return False
|
||||
from draftgeoutils.arcs import isWideAngle
|
||||
|
||||
|
||||
def findClosest(basepoint, pointslist):
|
||||
@@ -1485,25 +1458,7 @@ def circleFrom2PointsRadius(p1, p2, radius):
|
||||
else: return None
|
||||
|
||||
|
||||
def arcFrom2Pts(firstPt, lastPt, center, axis=None):
|
||||
"""Build an arc with center and 2 points, can be oriented with axis."""
|
||||
|
||||
radius1 = firstPt.sub(center).Length
|
||||
radius2 = lastPt.sub(center).Length
|
||||
if round(radius1-radius2,4) != 0 : # (PREC = 4 = same as Part Module), Is it possible ?
|
||||
return None
|
||||
|
||||
thirdPt = Vector(firstPt.sub(center).add(lastPt).sub(center))
|
||||
thirdPt.normalize()
|
||||
thirdPt.scale(radius1,radius1,radius1)
|
||||
thirdPt = thirdPt.add(center)
|
||||
newArc = Part.Edge(Part.Arc(firstPt,thirdPt,lastPt))
|
||||
if not axis is None and newArc.Curve.Axis.dot(axis) < 0 :
|
||||
thirdPt = thirdPt.sub(center)
|
||||
thirdPt.scale(-1,-1,-1)
|
||||
thirdPt = thirdPt.add(center)
|
||||
newArc = Part.Edge(Part.Arc(firstPt,thirdPt,lastPt))
|
||||
return newArc
|
||||
from draftgeoutils.arcs import arcFrom2Pts
|
||||
|
||||
|
||||
#############################33 to include
|
||||
|
||||
104
src/Mod/Draft/draftgeoutils/arcs.py
Normal file
104
src/Mod/Draft/draftgeoutils/arcs.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2009, 2010 Yorik van Havre <yorik@uncreated.net> *
|
||||
# * Copyright (c) 2009, 2010 Ken Cline <cline@frii.com> *
|
||||
# * *
|
||||
# * This file is part of the FreeCAD CAx development system. *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * FreeCAD is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with FreeCAD; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
"""Provides various functions for arc operations."""
|
||||
## @package arcs
|
||||
# \ingroup DRAFTGEOUTILS
|
||||
# \brief Provides various functions for arc operations.
|
||||
|
||||
import lazy_loader.lazy_loader as lz
|
||||
import math
|
||||
|
||||
import FreeCAD
|
||||
import DraftVecUtils
|
||||
|
||||
from draftgeoutils.general import geomType
|
||||
|
||||
# Delay import of module until first use because it is heavy
|
||||
Part = lz.LazyLoader("Part", globals(), "Part")
|
||||
|
||||
|
||||
def isClockwise(edge, ref=None):
|
||||
"""Return True if a circle-based edge has a clockwise direction."""
|
||||
if not geomType(edge) == "Circle":
|
||||
return True
|
||||
|
||||
v1 = edge.Curve.tangent(edge.ParameterRange[0])[0]
|
||||
if DraftVecUtils.isNull(v1):
|
||||
return True
|
||||
|
||||
# we take an arbitrary other point on the edge that has little chances
|
||||
# to be aligned with the first one
|
||||
v2 = edge.Curve.tangent(edge.ParameterRange[0] + 0.01)[0]
|
||||
n = edge.Curve.Axis
|
||||
# if that axis points "the wrong way" from the reference, we invert it
|
||||
if not ref:
|
||||
ref = FreeCAD.Vector(0, 0, 1)
|
||||
if n.getAngle(ref) > math.pi/2:
|
||||
n = n.negative()
|
||||
|
||||
if DraftVecUtils.angle(v1, v2, n) < 0:
|
||||
return False
|
||||
|
||||
if n.z < 0:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def isWideAngle(edge):
|
||||
"""Return True if the given edge is an arc with angle > 180 degrees."""
|
||||
if geomType(edge) != "Circle":
|
||||
return False
|
||||
|
||||
r = edge.Curve.Radius
|
||||
total = 2*r*math.pi
|
||||
|
||||
if edge.Length > total/2:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def arcFrom2Pts(firstPt, lastPt, center, axis=None):
|
||||
"""Build an arc with center and 2 points, can be oriented with axis."""
|
||||
radius1 = firstPt.sub(center).Length
|
||||
radius2 = lastPt.sub(center).Length
|
||||
|
||||
# (PREC = 4 = same as Part Module), Is it possible?
|
||||
if round(radius1-radius2, 4) != 0:
|
||||
return None
|
||||
|
||||
thirdPt = FreeCAD.Vector(firstPt.sub(center).add(lastPt).sub(center))
|
||||
thirdPt.normalize()
|
||||
thirdPt.scale(radius1, radius1, radius1)
|
||||
thirdPt = thirdPt.add(center)
|
||||
newArc = Part.Edge(Part.Arc(firstPt, thirdPt, lastPt))
|
||||
|
||||
if axis and newArc.Curve.Axis.dot(axis) < 0:
|
||||
thirdPt = thirdPt.sub(center)
|
||||
thirdPt.scale(-1, -1, -1)
|
||||
thirdPt = thirdPt.add(center)
|
||||
newArc = Part.Edge(Part.Arc(firstPt, thirdPt, lastPt))
|
||||
|
||||
return newArc
|
||||
Reference in New Issue
Block a user