def get_line_features(lmk): ps = [Vec2(0, 0), Vec2(1, 0)] ls = LineSegment.from_points(ps) dist_start = lmk.distance_to(ls.start) dist_end = lmk.distance_to(ls.end) dist_mid = lmk.distance_to(ls.mid) tl = Line.from_normal(ls.direction, ls.start.x) dir_start = -1 if tl.point_left(lmk) else 1 tl = Line.from_normal(ls.direction, ls.end.x) dir_end = -1 if tl.point_left(lmk) else 1 tl = Line.from_normal(ls.direction, ls.mid.x) dir_mid = -1 if tl.point_left(lmk) else 1 return { 'dist_start': dist_start, 'dist_mid': dist_mid, 'dist_end': dist_end, 'dir_start': dir_start, 'dir_mid': dir_mid, 'dir_end': dir_end, }
def mirror_point(point_a, point_b, point_to_mirror): vec_a = Vec2(point_a[0], point_a[1]) vec_b = Vec2(point_b[0] - point_a[0], point_b[1] - point_a[1]) line = Line(vec_a, vec_b) org_vec = Vec2(point_to_mirror[0], point_to_mirror[1]) reflect_vec = line.reflect(org_vec) return reflect_vec.x, reflect_vec.y
def get_primary_axes(self): return [ Line.from_points([ Vec2(self.rect.min_point.x, self.rect.center.y), Vec2(self.rect.max_point.x, self.rect.center.y) ]), Line.from_points([ Vec2(self.rect.center.x, self.rect.min_point.y), Vec2(self.rect.center.x, self.rect.max_point.y) ]) ]
def intersects(self, shape: Polygon) -> bool: """Check whether this wall intersects a Polygon.""" segment_line = self.line_segment.line vertex1, vertex2 = self.line_segment.points relative_sides = ((p, segment_line.point_left(p)) for p in shape) for (p1, s1), (p2, s2) in islice(pairwise(cycle(relative_sides)), len(shape)): if s1 is not s2: # p1 and p2 are on opposite sides of the line that contains this wall edge = Line.from_points([p1, p2]) if edge.point_left(vertex1) is not edge.point_left(vertex2): return True return False
def get_primary_axes(self): return [Line.from_points([Vec2(self.rect.min_point.x, self.rect.center.y), Vec2(self.rect.max_point.x, self.rect.center.y)]), Line.from_points([Vec2(self.rect.center.x, self.rect.min_point.y), Vec2(self.rect.center.x, self.rect.max_point.y)])]
def distance_to(x1, y1, x2, y2, px, py): p = Vec2(x1, y1) direction = Vec2(x2 - x1, y2 - y1) line = Line(p, direction) return abs(line.distance_to(Vec2(px, py)))
def distance_to(x1,y1,x2,y2,px,py): p = Vec2(x1,y1) direction = Vec2(x2-x1,y2-y1) line = Line(p, direction) return abs(line.distance_to(Vec2(px,py)))
''' Created on Oct 23, 2012 @author: Nguyen Huu Hiep ''' from planar import Vec2 from planar.line import Line class LineOperator: @staticmethod def distance_to(x1,y1,x2,y2,px,py): p = Vec2(x1,y1) direction = Vec2(x2-x1,y2-y1) line = Line(p, direction) return abs(line.distance_to(Vec2(px,py))) if __name__ == "__main__": p = Vec2(0,0) direction = Vec2(1,1) line = Line(p, direction) print line.distance_to(Vec2(0,1)) print line.distance_to(Vec2(1,0)) print line.distance_to(Vec2(2,2))
''' Created on Oct 23, 2012 @author: Nguyen Huu Hiep ''' from planar import Vec2 from planar.line import Line class LineOperator: @staticmethod def distance_to(x1, y1, x2, y2, px, py): p = Vec2(x1, y1) direction = Vec2(x2 - x1, y2 - y1) line = Line(p, direction) return abs(line.distance_to(Vec2(px, py))) if __name__ == "__main__": p = Vec2(0, 0) direction = Vec2(1, 1) line = Line(p, direction) print line.distance_to(Vec2(0, 1)) print line.distance_to(Vec2(1, 0)) print line.distance_to(Vec2(2, 2))
def get_primary_axes(self): return [Line(self.location, Vec2(1,0)), Line(self.location, Vec2(0,1))]