Previous: ``` startProfileAt([x, y], %) startProfileAt([x, y], sketch001) ``` New: ``` startProfile(%, at = [x, y]) startProfile(sketch001, at = [x, y]) ```
83 lines
158 KiB
Markdown
83 lines
158 KiB
Markdown
---
|
|
title: "intersect"
|
|
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.
|
|
|
|
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.
|
|
|
|
```js
|
|
intersect(
|
|
solids: [Solid],
|
|
tolerance?: number,
|
|
): [Solid]
|
|
```
|
|
|
|
|
|
### Arguments
|
|
|
|
| Name | Type | Description | Required |
|
|
|----------|------|-------------|----------|
|
|
| `solids` | [`[Solid]`](/docs/kcl/types/Solid) | The solids to intersect. | Yes |
|
|
| `tolerance` | [`number`](/docs/kcl/types/number) | The tolerance to use for the intersection operation. | No |
|
|
|
|
### Returns
|
|
|
|
[`[Solid]`](/docs/kcl/types/Solid)
|
|
|
|
|
|
### Examples
|
|
|
|
```js
|
|
// 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([0, 0], 10)
|
|
part002 = cube([7, 3], 5)
|
|
|> translate(z = 1)
|
|
|
|
intersectedPart = intersect([part001, part002])
|
|
```
|
|
|
|

|
|
|
|
```js
|
|
// 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([0, 0], 10)
|
|
part002 = cube([7, 3], 5)
|
|
|> translate(z = 1)
|
|
|
|
// This is the equivalent of: intersect([part001, part002])
|
|
intersectedPart = part001 & part002
|
|
```
|
|
|
|

|
|
|
|
|