You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a (generative design of buildings) project I made a method to parametrize rectangles according to height, width, centroid and orientation if any, a bit similarly to rhino/gh.
I thought it might be a cool small thing to add to compas, wanted your opinion on that, and also how (will be a Rectangle class ?)
Thx,
Jo
Here's the code :
def rectangle_xy(width, height, centroid, angle=None):
"""
Create a rectangle polygon and apply rotation transformation.
Parameters:
width (float): Width of the rectangle.
height (float): Height of the rectangle.
centroid (compas.geometry.Point): The centroid point of the rectangle.
angle (float, optional): Angle of rotation in degrees. Default is None.
Returns:
compas.geometry.Polygon: The transformed rectangle polygon.
"""
xc = centroid.x
yc = centroid.y
# Define the vertices of the rectangle
vertices = [Point(xc - width / 2, yc - height / 2),
Point(xc - width / 2, yc + height / 2),
Point(xc + width / 2, yc + height / 2),
Point(xc + width / 2, yc - height / 2)]
# Create the rectangle polygon
rectangle = Polygon(vertices)
if angle is not None:
# Create a rotation transformation
R = Rotation.from_axis_and_angle(Vector.Zaxis(), math.radians(angle), point=centroid)
# Apply the rotation transformation to the rectangle
rectangle.transform(R)
return rectangle
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
For a (generative design of buildings) project I made a method to parametrize rectangles according to height, width, centroid and orientation if any, a bit similarly to rhino/gh.
I thought it might be a cool small thing to add to compas, wanted your opinion on that, and also how (will be a Rectangle class ?)
Thx,
Jo
Here's the code :
def rectangle_xy(width, height, centroid, angle=None):
"""
Create a rectangle polygon and apply rotation transformation.
Beta Was this translation helpful? Give feedback.
All reactions