Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft: move functions to draftgeoutils.arcs
- Loading branch information
1 parent
e7b586e
commit 0e862cf
Showing
3 changed files
with
108 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |