Skip to content

Commit

Permalink
beam frame consistent with btlx reference frame
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Jul 4, 2024
1 parent 79798ea commit d6fed8e
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/compas_timber/elements/beam.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math

import compas
from compas.geometry import Box
from compas.geometry import Brep
from compas.geometry import Frame
Expand All @@ -20,6 +21,22 @@
from .features import FeatureApplicationError


def _create_box(frame, xsize, ysize, zsize):
boxframe = _from_corner_to_center(frame, xsize, ysize, zsize)
return Box(xsize, ysize, zsize, frame=boxframe)


def _from_corner_to_center(corner, xsize, ysize, zsize):
result = corner.copy()
x_offset = result.xaxis * xsize * 0.5
y_offset = result.yaxis * ysize * 0.5
z_offset = result.zaxis * zsize * 0.5
result.point += x_offset
result.point += y_offset
result.point += z_offset
return result


class Beam(Element):
"""
A class to represent timber beams (studs, slats, etc.) with rectangular cross-sections.
Expand Down Expand Up @@ -317,11 +334,19 @@ def from_centerline(cls, centerline, width, height, z_vector=None):
y_vector = Vector(*cross_vectors(x_vector, z_vector)) * -1.0
if y_vector.length < TOL.absolute:
raise ValueError("The given z_vector seems to be parallel to the given centerline.")
frame = Frame(centerline.start, x_vector, y_vector)
frame_origin = cls._get_beam_origin_from_centerline(centerline, width, height)
frame = Frame(frame_origin, x_vector, z_vector)
length = centerline.length

return cls(frame, length, width, height)

@staticmethod
def _get_beam_origin_from_centerline(centerline, width, height):
origin = centerline.start.copy()
origin.y += width * 0.5
origin.z -= height * 0.5
return origin

@classmethod
def from_endpoints(cls, point_start, point_end, width, height, z_vector=None):
"""Creates a Beam from the given endpoints.
Expand Down

0 comments on commit d6fed8e

Please sign in to comment.