def auto_adjust_distance(self): s = self.settings v = self.view # adjust the distance to get a view of the whole object dimx = s.get("maxx") - s.get("minx") dimy = s.get("maxy") - s.get("miny") dimz = s.get("maxz") - s.get("minz") max_dim = max(max(dimx, dimy), dimz) distv = Point(v["distance"][0], v["distance"][1], v["distance"][2]).normalized() # The multiplier "1.25" is based on experiments. 1.414 (sqrt(2)) should # be roughly sufficient for showing the diagonal of any model. distv = distv.mul((max_dim * 1.25) / number(math.sin(v["fovy"] / 2))) self.view["distance"] = (distv.x, distv.y, distv.z) # Adjust the "far" distance for the camera to make sure, that huge # models (e.g. x=1000) are still visible. self.view["zfar"] = 100 * max_dim
def auto_adjust_distance(self): s = self.core v = self.view # adjust the distance to get a view of the whole object low_high = zip(*self._get_low_high_dims()) if (None, None) in low_high: return max_dim = max([high - low for low, high in low_high]) distv = Point(v["distance"][0], v["distance"][1], v["distance"][2]).normalized() # The multiplier "1.25" is based on experiments. 1.414 (sqrt(2)) should # be roughly sufficient for showing the diagonal of any model. distv = distv.mul((max_dim * 1.25) / number(math.sin(v["fovy"] / 2))) self.view["distance"] = (distv.x, distv.y, distv.z) # Adjust the "far" distance for the camera to make sure, that huge # models (e.g. x=1000) are still visible. self.view["zfar"] = 100 * max_dim
def intersect_circle_plane(center, radius, direction, triangle): # let n be the normal to the plane n = triangle.normal if n.dot(direction) == 0: return (None, None, INFINITE) # project onto z=0 n2 = Point(n.x, n.y, 0) if n2.norm == 0: (cp, d) = triangle.plane.intersect_point(direction, center) ccp = cp.sub(direction.mul(d)) return (ccp, cp, d) n2 = n2.normalized() # the cutter contact point is on the circle, where the surface normal is n ccp = center.add(n2.mul(-radius)) # intersect the plane with a line through the contact point (cp, d) = triangle.plane.intersect_point(direction, ccp) return (ccp, cp, d)