def move(self, moving_vec): """Move this sensor along a vector. Args: moving_vec: A ladybug_geometry Vector3D with the direction and distance to move the sensor. """ self.pos = tuple(pv.Point3D(*self.pos).move(moving_vec))
def reflect(self, plane): """Reflect this sensor across a plane. Args: plane: A ladybug_geometry Plane across which the object will be reflected. """ self.pos = tuple(pv.Point3D(*self.pos).reflect(plane.n, plane.o)) self.dir = tuple(pv.Vector3D(*self.dir).reflect(plane.n))
def scale(self, factor, origin=None): """Scale this sensor by a factor from an origin point. Args: factor: A number representing how much the object should be scaled. origin: A ladybug_geometry Point3D representing the origin from which to scale. If None, it will be scaled from the World origin (0, 0, 0). """ self.pos = tuple(pv.Point3D(*self.pos).scale(factor, origin))
def move(self, moving_vec): """Move this view along a vector. Args: moving_vec: A ladybug_geometry Vector3D with the direction and distance to move the view. """ position = pv.Point3D(*self.position) self.position = tuple(position.move(moving_vec))
def test_rotate(): sensor = Sensor((0, 0, 0), (1, 0, 0)) sensor.rotate(90, pv.Vector3D(0, 1, 1), pv.Point3D(0, 0, 20)) assert round(sensor.pos[0], 3) == -14.142 assert round(sensor.pos[1]) == -10 assert round(sensor.pos[2]) == 10 assert round(sensor.dir[0], 1) == 0.0 assert round(sensor.dir[1], 3) == 0.707 assert round(sensor.dir[2], 3) == -0.707
def test_rotate_xy(): sensor = Sensor((1, 0, 2), (2, 0, 0)) sensor.rotate_xy(90, pv.Point3D(0, 0, 0)) assert round(sensor.pos[0]) == 0 assert round(sensor.pos[1]) == 1 assert round(sensor.pos[2]) == 2 assert round(sensor.dir[0]) == 0 assert round(sensor.dir[1]) == 2 assert round(sensor.dir[2]) == 0
def test_reflect(): sensor = Sensor((1, 0, 2), (2, 0, 0)) sensor.reflect(Plane(pv.Vector3D(1, 0, 0), pv.Point3D(0, 0, 0))) assert round(sensor.pos[0]) == -1 assert round(sensor.pos[1]) == 0 assert round(sensor.pos[2]) == 2 assert round(sensor.dir[0]) == -2 assert round(sensor.dir[1]) == 0 assert round(sensor.dir[2]) == 0
def rotate_xy(self, angle, origin): """Rotate this sensor counterclockwise in the world XY plane by a certain angle. Args: angle: An angle in degrees. origin: A ladybug_geometry Point3D for the origin around which the object will be rotated. """ rad_angle = math.radians(angle) self.pos = tuple(pv.Point3D(*self.pos).rotate_xy(rad_angle, origin)) self.dir = tuple(pv.Vector3D(*self.dir).rotate_xy(rad_angle))
def scale(self, factor, origin=None): """Scale this view by a factor from an origin point. Args: factor: A number representing how much the object should be scaled. origin: A ladybug_geometry Point3D representing the origin from which to scale. If None, it will be scaled from the World origin (0, 0, 0). """ view_position = pv.Point3D(*self.position) self.position = view_position.scale(factor, origin) self.direction = pv.Vector3D(*self.direction) * factor self.up_vector = pv.Vector3D(*self.up_vector) * factor
def test_rotate(): v = View('test_view', (0, 0, 0), (1, 0, 0), (0, 0, 1)) v.rotate(90, pv.Vector3D(0, 1, 1), pv.Point3D(0, 0, 20)) assert round(v.position[0], 3) == -14.142 assert round(v.position[1]) == -10 assert round(v.position[2]) == 10 assert round(v.up_vector[0], 3) == 0.707 assert round(v.up_vector[1], 1) == 0.5 assert round(v.up_vector[2], 1) == 0.5 assert round(v.direction[0], 1) == 0.0 assert round(v.direction[1], 3) == 0.707 assert round(v.direction[2], 3) == -0.707
def rotate(self, angle, axis, origin): """Rotate this sensor by a certain angle around an axis and origin. Args: angle: An angle for rotation in degrees. axis: Rotation axis as a Vector3D. origin: A ladybug_geometry Point3D for the origin around which the object will be rotated. """ rad_angle = math.radians(angle) self.pos = tuple(pv.Point3D(*self.pos).rotate(axis, rad_angle, origin)) self.dir = tuple(pv.Vector3D(*self.dir).rotate(axis, rad_angle))
def test_reflect(): v = View('test_view', (1, 0, 2), (2, 0, 0), (0, 0, 3)) v.reflect(Plane(pv.Vector3D(1, 0, 0), pv.Point3D(0, 0, 0))) assert round(v.position[0]) == -1 assert round(v.position[1]) == 0 assert round(v.position[2]) == 2 assert round(v.up_vector[0]) == 0 assert round(v.up_vector[1]) == 0 assert round(v.up_vector[2]) == 3 assert round(v.direction[0]) == -2 assert round(v.direction[1]) == 0 assert round(v.direction[2]) == 0
def test_rotate_xy(): v = View('test_view', (1, 0, 2), (2, 0, 0), (0, 0, 3)) v.rotate_xy(90, pv.Point3D(0, 0, 0)) assert round(v.position[0]) == 0 assert round(v.position[1]) == 1 assert round(v.position[2]) == 2 assert round(v.up_vector[0]) == 0 assert round(v.up_vector[1]) == 0 assert round(v.up_vector[2]) == 3 assert round(v.direction[0]) == 0 assert round(v.direction[1]) == 2 assert round(v.direction[2]) == 0
def reflect(self, plane): """Reflect this view across a plane. Args: plane: A ladybug_geometry Plane across which the object will be reflected. """ view_up_vector = pv.Vector3D(*self.up_vector) view_position = pv.Point3D(*self.position) view_direction = pv.Vector3D(*self.direction) view_plane = Plane(n=view_up_vector, o=view_position, x=view_direction) ref_plane = view_plane.reflect(plane.n, plane.o) self._apply_plane_properties(ref_plane, view_direction, view_up_vector)
def test_rotate(): sensor = Sensor((0, 0, 0), (1, 0, 0)) sensors = [ Sensor((0, 0, 0), (0, 0, 1)), Sensor((0, 0, 10), (0, 0, 1)), sensor ] sg = SensorGrid('sg_1', sensors) sg.rotate(90, pv.Vector3D(0, 1, 1), pv.Point3D(0, 0, 20)) assert round(sensor.pos[0], 3) == -14.142 assert round(sensor.pos[1]) == -10 assert round(sensor.pos[2]) == 10 assert round(sensor.dir[0], 1) == 0.0 assert round(sensor.dir[1], 3) == 0.707 assert round(sensor.dir[2], 3) == -0.707
def test_rotate_xy(): sensor = Sensor((1, 0, 2), (2, 0, 0)) sensors = [ Sensor((0, 0, 0), (0, 0, 1)), Sensor((0, 0, 10), (0, 0, 1)), sensor ] sg = SensorGrid('sg_1', sensors) sg.rotate_xy(90, pv.Point3D(0, 0, 0)) assert round(sensor.pos[0]) == 0 assert round(sensor.pos[1]) == 1 assert round(sensor.pos[2]) == 2 assert round(sensor.dir[0]) == 0 assert round(sensor.dir[1]) == 2 assert round(sensor.dir[2]) == 0
def test_reflect(): sensor = Sensor((1, 0, 2), (2, 0, 0)) sensors = [ Sensor((0, 0, 0), (0, 0, 1)), Sensor((0, 0, 10), (0, 0, 1)), sensor ] sg = SensorGrid('sg_1', sensors) sg.reflect(Plane(pv.Vector3D(1, 0, 0), pv.Point3D(0, 0, 0))) assert round(sensor.pos[0]) == -1 assert round(sensor.pos[1]) == 0 assert round(sensor.pos[2]) == 2 assert round(sensor.dir[0]) == -2 assert round(sensor.dir[1]) == 0 assert round(sensor.dir[2]) == 0
def rotate_xy(self, angle, origin=None): """Rotate this view counterclockwise in the world XY plane by a certain angle. Args: angle: An angle in degrees. origin: A ladybug_geometry Point3D for the origin around which the object will be rotated. If None, self.position is used. (Default: None). """ view_up_vector = pv.Vector3D(*self.up_vector) view_position = pv.Point3D(*self.position) view_direction = pv.Vector3D(*self.direction) view_plane = Plane(n=view_up_vector, o=view_position, x=view_direction) position = origin if origin is not None else view_position rotated_plane = view_plane.rotate_xy(math.radians(angle), position) self._apply_plane_properties(rotated_plane, view_direction, view_up_vector)
def rotate(self, angle, axis=None, origin=None): """Rotate this view by a certain angle around an axis and origin. Args: angle: An angle for rotation in degrees. axis: Rotation axis as a Vector3D. If None, self.up_vector will be used. (Default: None). origin: A ladybug_geometry Point3D for the origin around which the object will be rotated. If None, self.position is used. (Default: None). """ view_up_vector = pv.Vector3D(*self.up_vector) view_position = pv.Point3D(*self.position) view_direction = pv.Vector3D(*self.direction) view_plane = Plane(n=view_up_vector, o=view_position, x=view_direction) axis = axis if axis is not None else view_up_vector position = origin if origin is not None else view_position rotated_plane = view_plane.rotate(axis, math.radians(angle), position) self._apply_plane_properties(rotated_plane, view_direction, view_up_vector)