Make a rectangle for each item on the stack. :param xLen: length in the x direction (in workplane coordinates) :param yLen: length in the y direction (in workplane coordinates) :param centered: If True, the rectangle will be centered around the reference p
(
self: T,
xLen: float,
yLen: float,
centered: Union[bool, Tuple[bool, bool]] = True,
forConstruction: bool = False,
)
| 2514 | return self._combineWithBase(res, combine, clean) |
| 2515 | |
| 2516 | def rect( |
| 2517 | self: T, |
| 2518 | xLen: float, |
| 2519 | yLen: float, |
| 2520 | centered: Union[bool, Tuple[bool, bool]] = True, |
| 2521 | forConstruction: bool = False, |
| 2522 | ) -> T: |
| 2523 | """ |
| 2524 | Make a rectangle for each item on the stack. |
| 2525 | |
| 2526 | :param xLen: length in the x direction (in workplane coordinates) |
| 2527 | :param yLen: length in the y direction (in workplane coordinates) |
| 2528 | :param centered: If True, the rectangle will be centered around the reference |
| 2529 | point. If False, the corner of the rectangle will be on the reference point and |
| 2530 | it will extend in the positive x and y directions. Can also use a 2-tuple to |
| 2531 | specify centering along each axis. |
| 2532 | :param forConstruction: should the new wires be reference geometry only? |
| 2533 | :type forConstruction: true if the wires are for reference, false if they are creating part |
| 2534 | geometry |
| 2535 | :return: a new CQ object with the created wires on the stack |
| 2536 | |
| 2537 | A common use case is to use a for-construction rectangle to define the centers of a hole |
| 2538 | pattern:: |
| 2539 | |
| 2540 | s = Workplane().rect(4.0, 4.0, forConstruction=True).vertices().circle(0.25) |
| 2541 | |
| 2542 | Creates 4 circles at the corners of a square centered on the origin. |
| 2543 | |
| 2544 | Negative values for xLen and yLen are permitted, although they only have an effect when |
| 2545 | centered is False. |
| 2546 | |
| 2547 | Future Enhancements: |
| 2548 | * project points not in the workplane plane onto the workplane plane |
| 2549 | """ |
| 2550 | |
| 2551 | if isinstance(centered, bool): |
| 2552 | centered = (centered, centered) |
| 2553 | |
| 2554 | offset = Vector() |
| 2555 | if not centered[0]: |
| 2556 | offset += Vector(xLen / 2, 0, 0) |
| 2557 | if not centered[1]: |
| 2558 | offset += Vector(0, yLen / 2, 0) |
| 2559 | |
| 2560 | points = [ |
| 2561 | Vector(xLen / -2.0, yLen / -2.0, 0), |
| 2562 | Vector(xLen / 2.0, yLen / -2.0, 0), |
| 2563 | Vector(xLen / 2.0, yLen / 2.0, 0), |
| 2564 | Vector(xLen / -2.0, yLen / 2.0, 0), |
| 2565 | ] |
| 2566 | |
| 2567 | points = [x + offset for x in points] |
| 2568 | |
| 2569 | # close the wire |
| 2570 | points.append(points[0]) |
| 2571 | |
| 2572 | w = Wire.makePolygon(points, forConstruction) |
| 2573 |