Commit 980006e7 authored by sumpfralle's avatar sumpfralle

added a function for projecting a polygon onto a plane


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@640 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent e0959861
......@@ -40,6 +40,15 @@ class Plane(TransformableContainer):
def __repr__(self):
return "Plane<%s,%s>" % (self.p, self.n)
def __cmp__(self, other):
if self.__class__ == other.__class__:
if self.p == other.p:
return cmp(self.n, other.n)
else:
return cmp(self.p, other.p)
else:
return cmp(str(self), str(other))
def next(self):
yield self.p
yield self.n
......
......@@ -26,15 +26,18 @@ from pycam.Geometry.Plane import Plane
from pycam.Geometry import TransformableContainer
from pycam.Geometry.utils import number, epsilon
import pycam.Geometry.Matrix as Matrix
import pycam.Utils.log
import math
log = pycam.Utils.log.get_logger()
class Polygon(TransformableContainer):
def __init__(self, plane=None):
super(Polygon, self).__init__()
# TODO: derive the plane from the appended points
if plane is None:
# the default plane points upwards along the z axis
plane = Plane(Point(0, 0, 0), Point(0, 0, 1))
self.plane = plane
self._points = []
......@@ -648,3 +651,18 @@ class Polygon(TransformableContainer):
else:
return None
def get_plane_projection(self, plane):
if plane == self.plane:
return self
elif plane.n.dot(self.plane.n) == 0:
log.warn("Polygon projection onto plane: orthogonal projection " \
+ "is not possible")
return None
else:
result = Polygon(plane)
for line in self.get_lines():
p1, dist = plane.intersect_point(plane.n, line.p1)
p2, dist = plane.intersect_point(plane.n, line.p2)
result.append(Line(p1, p2))
return result
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment