예제 #1
0
    def from_data(cls, data):
        """Construct a cone from its data representation.

        Parameters
        ----------
        data : :obj:`dict`
            The data dictionary.

        Returns
        -------
        Cone
            The constructed cone.

        Examples
        --------
        >>> from compas.geometry import Cone
        >>> from compas.geometry import Circle
        >>> from compas.geometry import Plane
        >>> data = {'circle': Circle(Plane.worldXY(), 5).data, 'height': 7.}
        >>> cone = Cone.from_data(data)

        """
        cone = cls(Circle(Plane.worldXY(), 1), 1)
        cone.data = data
        return cone
예제 #2
0
    def data(self):
        """Returns the data dictionary that represents the torus.

        Returns
        -------
        dict
            The torus data.

        Examples
        --------
        >>> from compas.geometry import Plane
        >>> from compas.geometry import Torus
        >>> torus = Torus(Plane.worldXY(), 5, 2)
        >>> sdict = {'plane': Plane.worldXY().data, 'radius_axis': 5., 'radius_pipe': 2.}
        >>> sdict == torus.data
        True

        """
        return {'plane': Plane.worldXY().to_data(),
                'radius_axis': self.radius_axis,
                'radius_pipe': self.radius_pipe}
예제 #3
0
    def from_data(cls, data):
        """Construct a torus from its data representation.

        Parameters
        ----------
        data : :obj:`dict`
            The data dictionary.

        Returns
        -------
        Torus
            The constructed torus.

        Examples
        --------
        >>> from compas.geometry import Torus
        >>> data = {'plane': Plane.worldXY().data, 'radius_axis': 4., 'radius_pipe': 1.}
        >>> torus = Torus.from_data(data)

        """
        torus = cls(Plane.worldXY(), 1, 1)
        torus.data = data
        return torus
예제 #4
0
파일: torus.py 프로젝트: yishizu/compas
        >>> from compas.geometry import Transformation
        >>> from compas.geometry import Torus
        >>> torus = Torus(Plane.worldXY(), 5, 2)
        >>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
        >>> T = Transformation.from_frame(frame)
        >>> torus_transformed = torus.transformed(T)

        """
        torus = self.copy()
        torus.transform(transformation)
        return torus


if __name__ == '__main__':
    from compas.geometry import Transformation

    torus = Torus(Plane.worldXY(), 5, 2)
    frame = Frame([5, 0, 0], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
    T = Transformation.from_frame(frame)
    torus.transform(T)
    print(torus)

    torus = Torus(Plane.worldXY(), 5, 2)
    print(torus.data)
    print(torus)
    torus = Torus.from_data(torus.data)
    print(torus)

    import doctest
    doctest.testmod()
예제 #5
0
        -------
        :class: `Capsule`
            The transformed copy of the current capsule.
        """
        capsule = self.copy()
        capsule.line.transform(transformation)
        return capsule


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":
    from compas.geometry import Transformation

    capsule = Capsule(Line((1, 2, 3), (4, 5, 6)), 1.3)
    frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
    print(frame.normal)
    T = Transformation.from_frame(frame)
    capsule.transform(T)
    print(capsule)

    print(Plane.worldXY().data)
    data = {'line': Line((1, 2, 3), (5, 4, 2)).data, 'radius': 1.2}
    capsule = Capsule.from_data(data)
    print(capsule)

    import doctest
    doctest.testmod()
예제 #6
0
파일: cylinder.py 프로젝트: Licini/compas
        >>> T = Transformation.from_frame(frame)
        >>> circle_transformed = cylinder.transformed(T)

        """
        cylinder = self.copy()
        cylinder.transform(transformation)
        return cylinder


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":
    from compas.geometry import Transformation

    cylinder = Cylinder(Circle(Plane.worldXY(), 5), 7)
    frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
    print(frame.normal)
    T = Transformation.from_frame(frame)
    cylinder.transform(T)
    print(cylinder)

    print(Plane.worldXY().data)
    data = {'circle': Circle(Plane.worldXY(), 5).data, 'height': 7.}
    cylinder = Cylinder.from_data(data)
    print(cylinder)

    import doctest
    doctest.testmod()
예제 #7
0
from compas.geometry import Plane
from compas_rhino.artists import BoxArtist
from compas_rhino.artists import FrameArtist
from compas_rhino.artists import MeshArtist
from compas_rhino.artists import PlaneArtist  # not implemented

from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame(Point(1, 1, 3), Vector(1, 0, 1), Vector(0, 1, 1))

# Create a Box with that frame
box = Box(frame, 2, 3, 6)

# create a plane for the projection
planexy = Plane.worldXY()

# Create a Projection (can be orthogonal, parallel or perspective)
P3 = Projection.from_plane(
    planexy)  # orthogonal Projection to project onto a plane
P4 = Projection.from_plane_and_direction(planexy, direction=Vector(
    -2, 2, 1))  # parallel projection
P5 = Projection.from_plane_and_point(planexy,
                                     Point(3, -3,
                                           -1))  # perspective Projection

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected3 = mesh.transformed(P3)
예제 #8
0
        """
        cone = self.copy()
        cone.transform(transformation)
        return cone


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":
    from compas.geometry import Frame
    from compas.geometry import Transformation
    from compas.geometry import Circle

    cone = Cone(Circle(Plane.worldXY(), 5), 7)
    frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
    print(frame.normal)
    T = Transformation.from_frame(frame)
    cone.transform(T)
    print(cone)

    print(Plane.worldXY().data)
    data = {'circle': Circle(Plane.worldXY(), 5).data, 'height': 7.}
    cone = Cone.from_data(data)
    print(cone)

    import doctest
    doctest.testmod()
예제 #9
0
from compas.geometry import Circle
from compas.geometry import Plane
from compas.geometry import Translation
from compas.geometry import Rotation
from compas.geometry import Frame

from compas_view2.app import App

assembly = Assembly()

a = Part(name='A',
         geometry=Box.from_width_height_depth(1, 1, 1))

b = Part(name='B',
         frame=Frame([0, 0, 1], [1, 0, 0], [0, 1, 0]),
         shape=Box.from_width_height_depth(1, 1, 1),
         features=[(Cylinder(Circle(Plane.worldXY(), 0.2), 1.0), 'difference')])

b.transform(Rotation.from_axis_and_angle([0, 0, 1], radians(45)))
b.transform(Translation.from_vector([0, 0, 1]))

assembly.add_part(a)
assembly.add_part(b)

assembly.add_connection(a, b)

viewer = App()
viewer.add(b.geometry)
viewer.add(b.frame)
viewer.show()