Commit 4030b765 authored by sumpfralle's avatar sumpfralle

fixed calculation of polygon's barycenter

fixed handling of polygon normal - its length may not be scaled
update support model after rotate, swap and flip


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@967 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 42afa989
......@@ -58,8 +58,10 @@ class Plane(TransformableContainer):
return 2
def reset_cache(self):
# nothing to be done (but required for TransformableContainer)
pass
# we need to prevent the "normal" from growing
norm = self.n.normalized()
if norm:
self.n = norm
def intersect_point(self, direction, point):
if (not direction is None) and (direction.norm != 1):
......
......@@ -21,7 +21,7 @@ along with PyCAM. If not, see <http://www.gnu.org/licenses/>.
"""
from pycam.Geometry.Line import Line
from pycam.Geometry.Point import Point
from pycam.Geometry.Point import Point, Vector
from pycam.Geometry.Plane import Plane
from pycam.Geometry import TransformableContainer, get_bisector
from pycam.Geometry.utils import number, epsilon
......@@ -41,7 +41,7 @@ class Polygon(TransformableContainer):
super(Polygon, self).__init__()
if plane is None:
# the default plane points upwards along the z axis
plane = Plane(Point(0, 0, 0), Point(0, 0, 1))
plane = Plane(Point(0, 0, 0), Vector(0, 0, 1))
self.plane = plane
self._points = []
self.is_closed = False
......@@ -168,9 +168,6 @@ class Polygon(TransformableContainer):
area = self.get_area()
if not area:
return None
# TODO: for now we just calculate the "middle of the outline" - the "barycenter" code below needs to be fixed
return Point((self.maxx + self.minx) / 2, (self.maxy + self.miny) / 2,
(self.maxz + self.minz) / 2)
# see: http://stackoverflow.com/questions/2355931/compute-the-centroid-of-a-3d-planar-polygon/2360507
# first: calculate cx and y
cxy, cxz, cyx, cyz, czx, czy = (0, 0, 0, 0, 0, 0)
......@@ -179,10 +176,10 @@ class Polygon(TransformableContainer):
p2 = self._points[(index + 1) % len(self._points)]
cxy += (p1.x + p2.x) * (p1.x * p2.y - p1.y * p2.x)
cxz += (p1.x + p2.x) * (p1.x * p2.z - p1.z * p2.x)
cyx += (p1.y + p2.y) * (p1.y * p2.x - p1.x * p2.y)
cyx += (p1.y + p2.y) * (p1.x * p2.y - p1.y * p2.x)
cyz += (p1.y + p2.y) * (p1.y * p2.z - p1.z * p2.y)
czx += (p1.z + p2.z) * (p1.z * p2.x - p1.x * p2.z)
czy += (p1.z + p2.z) * (p1.z * p2.y - p1.y * p2.z)
czy += (p1.z + p2.z) * (p1.y * p2.z - p1.z * p2.y)
if self.minz == self.maxz:
return Point(cxy / (6 * area), cyx / (6 * area), self.minz)
elif self.miny == self.maxy:
......
......@@ -536,7 +536,8 @@ class ProjectGui:
lambda widget, data: shift_model_button.grab_default())
self.gui.get_object(objname).connect("focus-out-event",
lambda widget, data: self.window.set_default(None))
self.gui.get_object("Shift To Origin").connect("clicked", self.shift_model, False)
self.gui.get_object("Shift To Origin").connect("clicked",
self.shift_model, False)
# scale model
scale_percent = self.gui.get_object("ScalePercent")
scale_button = self.gui.get_object("ScaleModelButton")
......@@ -2154,7 +2155,8 @@ class ProjectGui:
self.update_progress_bar("Transforming model")
self.model.transform_by_template(value,
callback=self.update_progress_bar)
self.update_view()
self.append_to_queue(self.update_support_model)
self.append_to_queue(self.update_view)
def _treeview_get_active_index(self, table, datalist):
if len(datalist) == 0:
......
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