* csg-upts Signed-off-by: Jess Frazelle <github@jessfraz.com> * base Signed-off-by: Jess Frazelle <github@jessfraz.com> * do the id shit Signed-off-by: Jess Frazelle <github@jessfraz.com> * tried to run Signed-off-by: Jess Frazelle <github@jessfraz.com> * csg-upts Signed-off-by: Jess Frazelle <github@jessfraz.com> * use bens samples Signed-off-by: Jess Frazelle <github@jessfraz.com> * use bens samples Signed-off-by: Jess Frazelle <github@jessfraz.com> * gen std Signed-off-by: Jess Frazelle <github@jessfraz.com> * gen std Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * updates Signed-off-by: Jess Frazelle <github@jessfraz.com> * fix; Signed-off-by: Jess Frazelle <github@jessfraz.com> --------- Signed-off-by: Jess Frazelle <github@jessfraz.com>
		
			
				
	
	
		
			111 lines
		
	
	
		
			246 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			111 lines
		
	
	
		
			246 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
---
 | 
						|
title: "union"
 | 
						|
excerpt: "Union two or more solids into a single solid."
 | 
						|
layout: manual
 | 
						|
---
 | 
						|
 | 
						|
Union two or more solids into a single solid.
 | 
						|
 | 
						|
 | 
						|
 | 
						|
```js
 | 
						|
union(
 | 
						|
  solids: [Solid],
 | 
						|
  tolerance?: number,
 | 
						|
): [Solid]
 | 
						|
```
 | 
						|
 | 
						|
 | 
						|
### Arguments
 | 
						|
 | 
						|
| Name | Type | Description | Required |
 | 
						|
|----------|------|-------------|----------|
 | 
						|
| `solids` | [`[Solid]`](/docs/kcl/types/Solid) | The solids to union. | Yes |
 | 
						|
| `tolerance` | [`number`](/docs/kcl/types/number) | The tolerance to use for the union operation. | No |
 | 
						|
 | 
						|
### Returns
 | 
						|
 | 
						|
[`[Solid]`](/docs/kcl/types/Solid)
 | 
						|
 | 
						|
 | 
						|
### Examples
 | 
						|
 | 
						|
```js
 | 
						|
// Union two cubes using the stdlib functions.
 | 
						|
 | 
						|
 | 
						|
fn cube(center, size) {
 | 
						|
  return startSketchOn(XY)
 | 
						|
    |> startProfileAt([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)
 | 
						|
 | 
						|
unionedPart = union([part001, part002])
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
```js
 | 
						|
// Union 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)
 | 
						|
    |> startProfileAt([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: union([part001, part002])
 | 
						|
unionedPart = part001 + part002
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
```js
 | 
						|
// Union two cubes using the more programmer-friendly operator.
 | 
						|
// 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)
 | 
						|
    |> startProfileAt([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: union([part001, part002])
 | 
						|
  // Programmers will understand `|` as a union operation, but mechanical engineers
 | 
						|
// will understand `+`, we made both work.
 | 
						|
unionedPart = part001 | part002
 | 
						|
```
 | 
						|
 | 
						|

 | 
						|
 | 
						|
 |