Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 43 additions & 29 deletions src/compas/geometry/shapes/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,35 +529,49 @@ def to_brep(self):
# Transformations
# ==========================================================================

# def transform(self, transformation):
# """Transform the box.

# Parameters
# ----------
# transformation : :class:`Transformation`
# The transformation used to transform the Box.

# Returns
# -------
# None

# Examples
# --------
# >>> box = Box(Frame.worldXY(), 1.0, 2.0, 3.0)
# >>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
# >>> T = Transformation.from_frame(frame)
# >>> box.transform(T)

# """
# self.frame.transform(transformation)
# # Always local scaling, non-uniform scaling based on frame not yet considered.
# Sc, _, _, _, _ = transformation.decomposed()
# scalex = Sc[0, 0]
# scaley = Sc[1, 1]
# scalez = Sc[2, 2]
# self.xsize *= scalex
# self.ysize *= scaley
# self.zsize *= scalez
def transform(self, transformation):
"""Transform the box.

Parameters
----------
transformation : :class:`Transformation`
The transformation used to transform the Box.

Returns
-------
None

Examples
--------
>>> from compas.geometry import Frame, Transformation, Scale
>>> box = Box(Frame.worldXY(), 1.0, 2.0, 3.0)
>>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15])
>>> T = Transformation.from_frame(frame)
>>> box.transform(T)
>>> S = Scale.from_factors([2.0, 3.0, 4.0])
>>> box = Box(1.0, 2.0, 3.0)
>>> box.transform(S)
>>> box.xsize
2.0
>>> box.ysize
6.0
>>> box.zsize
12.0

"""
# Extract scale component from the transformation
Sc, _, _, _, _ = transformation.decomposed()
scale_x = Sc.matrix[0][0]
scale_y = Sc.matrix[1][1]
scale_z = Sc.matrix[2][2]

# Apply scaling to dimensions
self.xsize *= scale_x
self.ysize *= scale_y
self.zsize *= scale_z

# Apply transformation to frame
self.frame.transform(transformation)

def scale(self, x, y=None, z=None):
"""Scale the box.
Expand Down
40 changes: 40 additions & 0 deletions src/compas/geometry/shapes/capsule.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,46 @@ def compute_faces(self): # type: () -> list[list[int]]
# Transformations
# =============================================================================

def transform(self, transformation):
"""Transform the capsule.

Parameters
----------
transformation : :class:`Transformation`
The transformation used to transform the capsule.

Returns
-------
None

Examples
--------
>>> from compas.geometry import Frame, Scale
>>> capsule = Capsule(radius=2.0, height=4.0)
>>> S = Scale.from_factors([2.0, 2.0, 3.0])
>>> capsule.transform(S)
>>> capsule.radius
4.0
>>> capsule.height
12.0

"""
# Extract scale component from the transformation
Sc, _, _, _, _ = transformation.decomposed()
scale_x = Sc.matrix[0][0]
scale_y = Sc.matrix[1][1]
scale_z = Sc.matrix[2][2]

# For a capsule aligned with Z-axis:
# - radius is affected by X and Y scaling (use average)
# - height is affected by Z scaling
average_radial_scale = (scale_x + scale_y) / 2.0
self.radius *= average_radial_scale
self.height *= scale_z

# Apply transformation to frame
self.frame.transform(transformation)

def scale(self, factor):
"""Scale the capsule.

Expand Down
40 changes: 40 additions & 0 deletions src/compas/geometry/shapes/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,46 @@ def to_brep(self):
# Transformations
# ==========================================================================

def transform(self, transformation):
"""Transform the cone.

Parameters
----------
transformation : :class:`Transformation`
The transformation used to transform the cone.

Returns
-------
None

Examples
--------
>>> from compas.geometry import Frame, Scale
>>> cone = Cone(radius=3.0, height=6.0)
>>> S = Scale.from_factors([2.0, 2.0, 3.0])
>>> cone.transform(S)
>>> cone.radius
6.0
>>> cone.height
18.0

"""
# Extract scale component from the transformation
Sc, _, _, _, _ = transformation.decomposed()
scale_x = Sc.matrix[0][0]
scale_y = Sc.matrix[1][1]
scale_z = Sc.matrix[2][2]

# For a cone aligned with Z-axis:
# - radius is affected by X and Y scaling (use average)
# - height is affected by Z scaling
average_radial_scale = (scale_x + scale_y) / 2.0
self.radius *= average_radial_scale
self.height *= scale_z

# Apply transformation to frame
self.frame.transform(transformation)

def scale(self, factor):
"""Scale the cone by multiplying the radius and height by a factor.

Expand Down
40 changes: 40 additions & 0 deletions src/compas/geometry/shapes/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,46 @@ def to_brep(self):
# Transformations
# =============================================================================

def transform(self, transformation):
"""Transform the cylinder.

Parameters
----------
transformation : :class:`Transformation`
The transformation used to transform the cylinder.

Returns
-------
None

Examples
--------
>>> from compas.geometry import Frame, Scale
>>> cylinder = Cylinder(radius=2.0, height=5.0)
>>> S = Scale.from_factors([2.0, 2.0, 3.0])
>>> cylinder.transform(S)
>>> cylinder.radius
4.0
>>> cylinder.height
15.0

"""
# Extract scale component from the transformation
Sc, _, _, _, _ = transformation.decomposed()
scale_x = Sc.matrix[0][0]
scale_y = Sc.matrix[1][1]
scale_z = Sc.matrix[2][2]

# For a cylinder aligned with Z-axis:
# - radius is affected by X and Y scaling (use average)
# - height is affected by Z scaling
average_radial_scale = (scale_x + scale_y) / 2.0
self.radius *= average_radial_scale
self.height *= scale_z

# Apply transformation to frame
self.frame.transform(transformation)

def scale(self, factor):
"""Scale the cylinder by multiplying the radius and height by a factor.

Expand Down
13 changes: 7 additions & 6 deletions src/compas/geometry/shapes/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,6 @@ def to_brep(self):
def transform(self, transformation):
"""Transform the shape.

Transformations of a shape are performed by applying the transformation to the frame of the shape.
Transformations of the shape with respect to its local coordinate system are not supported.
For this reason, only (combinations of) translations and rotations are supported.
To scale a shape, use the :meth:`Shape.scale` method.

Parameters
----------
transformation : :class:`Transformation`
Expand All @@ -360,6 +355,12 @@ def transform(self, transformation):
Returns
-------
None

Notes
-----
Subclasses must override this method to decompose the transformation,
extract the scale component, and apply it appropriately to their dimensions
before transforming the frame.

See Also
--------
Expand All @@ -368,7 +369,7 @@ def transform(self, transformation):
scale

"""
self.frame.transform(transformation)
raise NotImplementedError

def translate(self, vector):
"""Translate the shape.
Expand Down
36 changes: 36 additions & 0 deletions src/compas/geometry/shapes/sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,42 @@ def to_brep(self):
# Transformations
# =============================================================================

def transform(self, transformation):
"""Transform the sphere.

Parameters
----------
transformation : :class:`Transformation`
The transformation used to transform the sphere.

Returns
-------
None

Examples
--------
>>> from compas.geometry import Frame, Transformation, Scale
>>> sphere = Sphere(5.0)
>>> S = Scale.from_factors([2.0, 2.0, 2.0])
>>> sphere.transform(S)
>>> sphere.radius
10.0

"""
# Extract scale component from the transformation
Sc, _, _, _, _ = transformation.decomposed()
scale_x = Sc.matrix[0][0]
scale_y = Sc.matrix[1][1]
scale_z = Sc.matrix[2][2]

# For a sphere, use the average of the three scale factors
# to maintain the spherical shape
average_scale = (scale_x + scale_y + scale_z) / 3.0
self.radius *= average_scale

# Apply transformation to frame
self.frame.transform(transformation)

def scale(self, factor):
"""Scale the sphere.

Expand Down
22 changes: 22 additions & 0 deletions src/compas/geometry/shapes/torus.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,35 @@ def transform(self, transformation):
--------
>>> from compas.geometry import Frame
>>> from compas.geometry import Transformation
>>> from compas.geometry import Scale
>>> from compas.geometry import Torus
>>> torus = Torus(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.transform(T)
>>> torus = Torus(5, 2)
>>> S = Scale.from_factors([2.0, 2.0, 3.0])
>>> torus.transform(S)
>>> torus.radius_axis
10.0
>>> torus.radius_pipe
6.0

"""
# Extract scale component from the transformation
Sc, _, _, _, _ = transformation.decomposed()
scale_x = Sc.matrix[0][0]
scale_y = Sc.matrix[1][1]
scale_z = Sc.matrix[2][2]

# For a torus in the XY plane:
# - axis radius is affected by X and Y scaling (use average)
# - pipe radius is affected by Z scaling
average_planar_scale = (scale_x + scale_y) / 2.0
self.radius_axis *= average_planar_scale
self.radius_pipe *= scale_z

# Apply transformation to frame
self.frame.transform(transformation)

def scale(self, factor):
Expand Down
40 changes: 40 additions & 0 deletions src/compas/geometry/surfaces/planar.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,46 @@ def to_plane(self):
"""
return Plane(self.frame.point, self.frame.zaxis)

# =============================================================================
# Transformations
# =============================================================================

def transform(self, transformation):
"""Transform the planar surface.

Parameters
----------
transformation : :class:`Transformation`
The transformation used to transform the planar surface.

Returns
-------
None

Examples
--------
>>> from compas.geometry import Frame, PlanarSurface, Scale
>>> surface = PlanarSurface(xsize=1.0, ysize=2.0)
>>> S = Scale.from_factors([2.0, 3.0, 1.0])
>>> surface.transform(S)
>>> surface.xsize
2.0
>>> surface.ysize
6.0

"""
# Extract scale component from the transformation
Sc, _, _, _, _ = transformation.decomposed()
scale_x = Sc.matrix[0][0]
scale_y = Sc.matrix[1][1]

# Apply scaling to dimensions
self.xsize *= scale_x
self.ysize *= scale_y

# Apply transformation to frame
self.frame.transform(transformation)

# =============================================================================
# Methods
# =============================================================================
Expand Down
Loading
Loading