コード例 #1
0
def test_Face3D():
    pt1 = Point3D(0, 1)
    pt2 = Point3D(1, 2)
    pt3 = Point3D(2, 3)
    obj1 = Face3D([pt1, pt2, pt3])
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #2
0
def test_Polyline3D():
    pt1 = Point3D(0, 1)
    pt2 = Point3D(1, 2)
    pt3 = Point3D(2, 3)
    obj1 = Polyline3D([pt1, pt2, pt3], False)
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #3
0
def test_Polyface3D():
    pt1 = Point3D(0, 1)
    pt2 = Point3D(1, 1)
    pt3 = Point3D(1, 0)
    pt4 = Point3D(0, 1)
    obj1 = Polyface3D(vertices=[pt1, pt2, pt3, pt4], face_indices=[[[1]]])
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #4
0
def test_Mesh3D():
    pt1 = Point3D(0, 1)
    pt2 = Point3D(1, 1)
    pt3 = Point3D(1, 0)
    pt4 = Point3D(0, 1)
    obj1 = Mesh3D(vertices=(pt1, pt2, pt3, pt4), faces=[(0, 1, 2)])

    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #5
0
ファイル: pincam.py プロジェクト: saeranv/pincam
    def ray_hit_polygon(ray_pt, ray_dir, polygon):
        """Return hit point from ray and polygon, if intersection exists
        """

        boundary = [Point3D.from_array(p) for p in polygon]
        face = Face3D(boundary)

        #ipt1 = Pincam.ray_hit_plane2(ray_pt, ray_dir, face.centroid, face.normal)
        ipt = Pincam.ray_hit_plane(ray_pt, ray_dir, face.centroid, face.normal)
        #print(ipt1, ipt)
        if ipt is None:
            return None

        # Multiply all vertices by inverse orthobasis of plane 3d
        poly2d = face.boundary_polygon2d

        # Stack column vectors to make change of basis matrix
        z = np.cross(face.plane.x.to_array(), face.plane.y.to_array())
        basis_mtx = np.array([face.plane.x.to_array(),
                              face.plane.y.to_array(), z]).T
        # Transpose of orthonormal is it's inverse
        ibasis_mtx = basis_mtx.T
        ipt2d = np.matmul(ibasis_mtx, ipt - face.plane.o)
        ipt2d = Point2D(ipt2d[0], ipt2d[1])

        if not poly2d.is_point_inside(ipt2d):
            return None

        return np.array(ipt)
コード例 #6
0
def test_Sphere():
    pt1 = Point3D()
    obj1 = Sphere(pt1, 1)
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #7
0
def test_Cylinder():
    v1 = Point3D()
    axis = Vector3D(0, 0, 1)
    obj1 = Cylinder(v1, axis, 10)
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #8
0
def test_Cone():
    v1 = Point3D()
    axis = Vector3D(0, 0, 1)
    obj1 = Cone(v1, axis, 45)
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #9
0
def test_LineSegment3D():
    pt1 = Point3D()
    v1 = Vector3D(0, 1)
    obj1 = LineSegment3D(pt1, v1)
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1
コード例 #10
0
ファイル: pincam.py プロジェクト: saeranv/pincam
    def ray_hit_plane(ray_pt, ray_dir, plane_origin, plane_normal):
        """
        Ray hits plane .
        """
        ray_pt, ray_dir = Point3D.from_array(
            ray_pt), Point3D.from_array(ray_dir)
        pln_n, pln_o = Vector3D.from_array(
            plane_normal), Point3D.from_array(plane_origin)

        # Make geometries
        ray = Ray3D(ray_pt, ray_dir)
        plane = Plane(pln_n, pln_o)

        r = plane.intersect_line_ray(ray)

        if r is None:
            return r

        return np.array(r.to_array())
コード例 #11
0
def find_tfa_host_room(_tfa_srfc_geom, _hb_rooms):
    """Evaluates the Centoid of a TFA srf to see if it is inside an HB-Room """
    
    srfc_centroid_a = Rhino.Geometry.AreaMassProperties.Compute(_tfa_srfc_geom).Centroid
    
    # Note: move the centroid 'up' just a tiny bit, otherwise 'is_point_inside'
    # test will return False. Must not work if point is 'on' a surface...
    move_distance = 0.01
    srfc_centroid_b = Rhino.Geometry.Point3d(srfc_centroid_a.X, srfc_centroid_a.Y, srfc_centroid_a.Z + move_distance)

    # Also, to use 'is_point_inside' need to convert the Point to a Ladybug Point3D
    srfc_centroid_c = Point3D(srfc_centroid_b.X, srfc_centroid_b.Y, srfc_centroid_b.Z)

    host_room = None
    for room in _hb_rooms:
        if room.geometry.is_point_inside( srfc_centroid_c ):
            host_room = room.display_name
            break

    return srfc_centroid_a, host_room
コード例 #12
0
    def aerial_cameras(cls: Camera, bounds: List[Point3D],
                       centroid) -> List[Camera]:
        """Get four aerial cameras.

        Args:
            bounds: A list of Point3D objects representing bounds of the actors in the
                scene.
            centroid: A Point3D object representing the centroid of the actors.

        Returns:
            A list of Camera objects.
        """

        # find the top most z-cordinate in the model
        cord_point = {point.z: point for point in bounds}
        topmost_z_cord = cord_point[sorted(cord_point, reverse=True)[0]].z

        # move centroid to the level of top most z-cordinate
        centroid_moved = Point3D(centroid.x, centroid.y, topmost_z_cord)

        # distance of four cameras from centroid
        distances = [centroid.distance_to_point(pt) for pt in bounds]
        farthest_distance = sorted(distances, reverse=True)
        camera_distance = farthest_distance[0]

        # generate total four points at 45 degrees and -45 degrees on left and right
        # side of the centroid
        pt0 = Point3D(
            centroid_moved.x + math.cos(math.radians(45)) * camera_distance,
            centroid_moved.y + math.sin(math.radians(45)) * camera_distance,
            centroid_moved.z)
        pt1 = Point3D(
            centroid_moved.x + math.cos(math.radians(-45)) * camera_distance,
            centroid_moved.y + math.sin(math.radians(-45)) * camera_distance,
            centroid_moved.z)
        pt2 = Point3D(
            centroid_moved.x +
            math.cos(math.radians(45)) * camera_distance * -1,
            centroid_moved.y +
            math.sin(math.radians(45)) * camera_distance * -1,
            centroid_moved.z)
        pt3 = Point3D(
            centroid_moved.x +
            math.cos(math.radians(-45)) * camera_distance * -1,
            centroid_moved.y +
            math.sin(math.radians(-45)) * camera_distance * -1,
            centroid_moved.z)
        camera_points = [pt0, pt3, pt2, pt1]

        # get directions (vectors) from each point to the centroid
        directions = [
            LineSegment3D.from_end_points(pt, centroid).v
            for pt in camera_points
        ]

        # default camera identifiers
        names = ['45_degrees', '315_degrees', '225_degrees', '135_degrees']

        # create cameras from four points. These cameras look at the centroid.
        default_cameras = []
        for i in range(len(camera_points)):
            point = camera_points[i]
            direction = directions[i]
            default_cameras.append(
                cls(identifier=names[i],
                    position=(point.x, point.y, point.z),
                    direction=(direction.x, direction.y, direction.z),
                    up_vector=(0, 0, 1)))

        return default_cameras
コード例 #13
0
def test_Point3D():
    obj1 = Point3D()
    d = obj1.to_dict()
    obj2 = geometry_dict_to_object(d)

    assert obj2 == obj1