| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | """Provides various functions for inversive operations using a circle. |
| | |
| | http://en.wikipedia.org/wiki/Inversive_geometry |
| | """ |
| | |
| | |
| | |
| |
|
| | import lazy_loader.lazy_loader as lz |
| |
|
| | import FreeCAD as App |
| | import DraftVecUtils |
| |
|
| | from draftgeoutils.general import NORM, geomType |
| | from draftgeoutils.geometry import findDistance |
| |
|
| | |
| | Part = lz.LazyLoader("Part", globals(), "Part") |
| |
|
| | |
| | |
| |
|
| |
|
| | def pointInversion(circle, point): |
| | """Return the circle inversion of a point. |
| | |
| | It will return `None` if the given point is equal to the center |
| | of the circle. |
| | """ |
| | if geomType(circle) != "Circle" or isinstance(point, App.Vector): |
| | print("debug: pointInversion bad parameters!") |
| | return None |
| |
|
| | cen = circle.Curve.Center |
| | rad = circle.Curve.Radius |
| |
|
| | if DraftVecUtils.equals(cen, point): |
| | return None |
| |
|
| | |
| | |
| |
|
| | dist = DraftVecUtils.dist(point, cen) |
| | invDist = rad**2 / dist |
| |
|
| | invPoint = App.Vector(0, 0, point.z) |
| | invPoint.x = cen.x + (point.x - cen.x) * invDist / dist |
| | invPoint.y = cen.y + (point.y - cen.y) * invDist / dist |
| |
|
| | return invPoint |
| |
|
| |
|
| | def polarInversion(circle, edge): |
| | """Return the inversion pole of a line. The edge is the polar. |
| | |
| | The nearest point on the line is inversed. |
| | |
| | http://mathworld.wolfram.com/InversionPole.html |
| | """ |
| | if geomType(circle) != "Circle" or geomType(edge) != "Line": |
| | print("debug: circleInversionPole bad parameters! Must be a circle.") |
| | return None |
| |
|
| | nearest = circle.Curve.Center.add(findDistance(circle.Curve.Center, edge, False)) |
| | if nearest: |
| | inversionPole = pointInversion(circle, nearest) |
| | if inversionPole: |
| | return inversionPole |
| |
|
| | return None |
| |
|
| |
|
| | def circleInversion(circle, circle2): |
| | """Circle inversion of a circle, inverting the center point. |
| | |
| | Returns the new circle created from the inverted center of circle2. |
| | """ |
| | if geomType(circle) != "Circle" or geomType(circle2) != "Circle": |
| | print("debug: circleInversion bad parameters! Must be circles.") |
| | return None |
| |
|
| | cen1 = circle.Curve.Center |
| |
|
| | cen2 = circle2.Curve.Center |
| | rad2 = circle2.Curve.Radius |
| |
|
| | if DraftVecUtils.equals(cen1, cen2): |
| | return None |
| |
|
| | invCen2 = pointInversion(circle, cen2) |
| |
|
| | pointOnCircle2 = App.Vector.add(cen2, App.Vector(rad2, 0, 0)) |
| | invPointOnCircle2 = pointInversion(circle, pointOnCircle2) |
| |
|
| | return Part.Circle(invCen2, NORM, DraftVecUtils.dist(invCen2, invPointOnCircle2)) |
| |
|
| |
|
| | |
| |
|