88 lines
159 KiB
Markdown
88 lines
159 KiB
Markdown
---
|
|
title: "intersect"
|
|
subtitle: "Function in std::solid"
|
|
excerpt: "Intersect returns the shared volume between multiple solids, preserving only overlapping regions."
|
|
layout: manual
|
|
---
|
|
|
|
Intersect returns the shared volume between multiple solids, preserving only overlapping regions.
|
|
|
|
```kcl
|
|
intersect(
|
|
@solids: [Solid; 2+],
|
|
tolerance?: number(Length),
|
|
): [Solid; 1+]
|
|
```
|
|
|
|
Intersect computes the geometric intersection of multiple solid bodies,
|
|
returning a new solid representing the volume that is common to all input
|
|
solids. This operation is useful for determining shared material regions,
|
|
verifying fit, and analyzing overlapping geometries in assemblies.
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `solids` | `[Solid; 2+]` | The solids to intersect. | Yes |
|
|
| `tolerance` | [`number(Length)`](/docs/kcl-std/types/std-types-number) | Defines the smallest distance below which two entities are considered coincident, intersecting, coplanar, or similar. For most use cases, it should not be changed from its default value of 10^-7 millimeters. | No |
|
|
|
|
### Returns
|
|
|
|
[`[Solid; 1+]`](/docs/kcl-std/types/std-types-Solid)
|
|
|
|
|
|
### Examples
|
|
|
|
```kcl
|
|
// Intersect two cubes using the stdlib functions.
|
|
|
|
|
|
fn cube(center, size) {
|
|
return startSketchOn(XY)
|
|
|> startProfile(at = [center[0] - size, center[1] - size])
|
|
|> line(endAbsolute = [center[0] + size, center[1] - size])
|
|
|> line(endAbsolute = [center[0] + size, center[1] + size])
|
|
|> line(endAbsolute = [center[0] - size, center[1] + size])
|
|
|> close()
|
|
|> extrude(length = 10)
|
|
}
|
|
|
|
part001 = cube(center = [0, 0], size = 10)
|
|
part002 = cube(center = [7, 3], size = 5)
|
|
|> translate(z = 1)
|
|
|
|
intersectedPart = intersect([part001, part002])
|
|
|
|
```
|
|
|
|

|
|
|
|
```kcl
|
|
// Intersect two cubes using operators.
|
|
// NOTE: This will not work when using codemods through the UI.
|
|
// Codemods will generate the stdlib function call instead.
|
|
|
|
|
|
fn cube(center, size) {
|
|
return startSketchOn(XY)
|
|
|> startProfile(at = [center[0] - size, center[1] - size])
|
|
|> line(endAbsolute = [center[0] + size, center[1] - size])
|
|
|> line(endAbsolute = [center[0] + size, center[1] + size])
|
|
|> line(endAbsolute = [center[0] - size, center[1] + size])
|
|
|> close()
|
|
|> extrude(length = 10)
|
|
}
|
|
|
|
part001 = cube(center = [0, 0], size = 10)
|
|
part002 = cube(center = [7, 3], size = 5)
|
|
|> translate(z = 1)
|
|
|
|
// This is the equivalent of: intersect([part001, part002])
|
|
intersectedPart = part001 & part002
|
|
|
|
```
|
|
|
|

|
|
|
|
|