Skip to content

Center radius outside line

CenterRadiusOutsideLine

CenterRadiusOutsideLine(
    arc,
    draft,
    label=None,
    offset=0,
    sketch=None,
    mode=Mode.ADD,
)

Bases: BaseSketchObject

Creates a dimension line for an arc's radius

Parameters:

Name Type Description Default
arc Edge

Arc to measure

required
draft Draft

Instance of Draft dataclass

required
label str | None

A text string which will replace the length (or arc length) that would otherwise be extracted from the provided path. Providing a label is useful when illustrating a parameterized input where the name of an argument is desired not an actual measurement. Defaults to None.

None
offset float

A distance to displace the dimension line from the edge of the object

0
sketch Sketch | None

Optional context sketch

None
mode Mode

Combination mode. Defaults to Mode.ADD

ADD

Raises:

Type Description
BaseException

when provided arc don't have the GeomType.CIRCLE geom_type

Source code in src/bd_beams_and_bars/helpers/center_radius_outside_line.py
def __init__(
    self,
    arc: Edge,
    draft: Draft,
    label: str | None = None,
    offset: float = 0,
    sketch: Sketch | None = None,
    mode: Mode = Mode.ADD,
):
    context = BuildSketch._get_context(self)
    if sketch is None and not (context is None or context.sketch is None):
        sketch = context.sketch

    if arc.geom_type != GeomType.CIRCLE:
        raise BaseException(f"circle is not a CIRCLE: {arc.geom_type}. Maybe try with arc.edge()?")

    self.dimension = arc.radius

    # Circles have only 1 vertex
    half_point = self._half_point(arc)
    # Determine right/left side
    side = self._side(arc)

    # The dimension line starts at the center of the arc, to the middle of it.
    # From there, it goes horizontally, at least at the same X in the determined
    # direction.

    # Point at the most left or right, depending on side
    sorted_points = arc.vertices().sort_by(Axis.X)
    extremity_point = sorted_points[-1] if side == Side.RIGHT else sorted_points[0]

    line_points = [arc.arc_center, half_point]
    horizontal_line_end = extremity_point.X
    horizontal_line_end += offset if side == Side.RIGHT else -offset
    # Only create a line if it has a length
    if abs(horizontal_line_end - half_point.X) != 0:
        line_points.append((horizontal_line_end, half_point.Y))
    text_line = Polyline(*line_points)

    shaft = ShaftLine(path=text_line, width=draft.line_width)
    arrow_rotation = Line(arc.arc_center, half_point).tangent_angle_at(1)
    arrow = Pos(half_point) * ArrowHead(size=draft.arrow_length, head_type=draft.head_type, rotation=arrow_rotation)
    line_and_arrow = cast(Compound, arrow.fuse(shaft)).clean()

    label_str = label if label is not None else str(arc.radius)
    text_align = Align.MAX if side == Side.LEFT else Align.MIN
    label_shape = Text(
        txt=label_str,
        font_size=draft.font_size,
        font=draft.font,
        font_style=draft.font_style,
        align=(text_align, Align.CENTER),
    )

    label_x = (text_line @ 1).X
    label_x += draft.pad_around_text if side == Side.RIGHT else -draft.pad_around_text
    label_shape = Pos((label_x, (text_line @ 1).Y)) * label_shape

    r_line_sketch = Sketch(children=line_and_arrow + label_shape)

    super().__init__(obj=r_line_sketch, rotation=0, align=None, mode=mode)