def test_intersection_1(): l1 = Line() # X axis l2 = Line(direction_vector=Vector([0, 1, 0]), point=Point(0, 1, 0)) # Y-axis l3 = Line(direction_vector=Vector([-1, 1, 0]), point=Point(3, 0, 0)) assert l1.intersection(l2) == Point(0, 0, 0) assert l3.intersection(l2) == Point(0, 3, 0)
def get_intersected_neigbour(circles: [Circle], start_point: Point, end_point: Point, without=None): if without is None: without = [] line = Line([start_point, end_point]) _min = float('+inf') neigbour = None for circle in circles: if circle in without: continue intersection = line.intersection(circle) if not intersection.is_empty: minimal = Point(min(list(intersection.coords), key=lambda pair: pair[0] ** 2 + pair[1] ** 2)) distance = (start_point.x - minimal.x) ** 2 + (start_point.y - minimal.y) ** 2 if distance < _min: _min = distance neigbour = circle return neigbour
def generate_surface(self, radstep=None, angle_steps=None, rough_factor=4): radstep = radstep or self.radial_step angle_steps = angle_steps or self.angle_steps polys = [] for angle_index in range(rough_factor, angle_steps+1, rough_factor): lastrad = self.minor_radius for rad in frange(self.minor_radius+radstep*rough_factor, self.major_radius, radstep*rough_factor): pt1 = self.genxy(angle_index, rad) pt2 = self.genxy(angle_index-rough_factor, rad) pt3 = self.genxy(angle_index-rough_factor, lastrad) pt4 = self.genxy(angle_index, lastrad) poly1 = Line((pt1, pt2, pt3)) poly2 = Line((pt3, pt4, pt1)) polys.append(poly1) if not isinstance(poly1.intersection(poly2), Polygon): polys.append(poly2) lastrad = rad #print "maxdiff", maxdiff return PolySurface(polys)