# Creating decking with intersect\_with

**URL:** <https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253>\
**Category:** Ruby API\
**Created:** [January 22, 2021, 7:22pm UTC](https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253 "2021-01-22T19:22:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![calioptrix](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@calioptrix](https://forums.sketchup.com/u/calioptrix)\
**Post date:** [January 22, 2021, 7:22pm UTC](https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253/1 "2021-01-22T19:22:29Z")

</div>

I’m trying to convert a face into deck boards but can’t seem to figure out the proper way to use intersect\_with and work with the result. Here is the sample code I’m using to figure out how to do it. I create the faces of the deck boards (boardgroup), and the shape of the deck that I want it to be in (outlinegroup). I call intersect\_with and put the results into a third group (newgroup). I’m not sure how to remove the parts of the boards that are outside of the outline.

```auto
model = Sketchup.active_model
entities = model.active_entities
selection = model.selection

def face_make (group, pts, material)
  normal = [0,0,1]
 
  face = group.entities.add_face(pts)
 
  dot = face.normal.dot normal
  if dot < 0.0
    face.reverse!
  end
  
  face.material = material
  
  face
end

pts = []

#make the outline shape that we want to conform to
pts[0] = [5, 5, 0]
pts[1] = [5, 24, 0]
pts[2] = [63, 24, 0]
pts[3] = [63, 0, 0]
outlinegroup = entities.add_group
outline = face_make(outlinegroup, pts, "blue")

pts[0] = [0, 0, 0]
pts[1] = [0, 36, 0]
pts[2] = [5.5, 36, 0]
pts[3] = [5.5, 0, 0]

boardgroup = entities.add_group

for i in 0..10
  face_make(boardgroup, pts, "red")
  
  pts[0].x += 6
  pts[1].x += 6
  pts[2].x += 6
  pts[3].x += 6
end

newgroup = entities.add_group

boardgroup.entities.intersect_with(true, IDENTITY, newgroup.entities, IDENTITY, false, outlinegroup)

```

---

<div class="post-metadata">

**Author:** ![Neil\_Burkholder](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@Neil\_Burkholder](https://forums.sketchup.com/u/Neil_Burkholder)\
**Post date:** [January 23, 2021, 3:25am UTC](https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253/2 "2021-01-23T03:25:22Z")

</div>

You need to give your groups some thickness before the intersect.

```auto
boardgroup.entities.grep(Sketchup::Face).each { |f| f.pushpull 1 }
outlinegroup.entities.grep(Sketchup::Face).each { |f| f.pushpull 1 }
newgroup = boardgroup.intersect(outlinegroup)
newgroup.entities.grep(Sketchup::Face).each { |f| f.material = "red" }

```

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/c/a/cad38bca63adf966a2304609fee0ba98de7414cc.png)

---

<div class="post-metadata">

**Author:** ![calioptrix](https://avatars.discourse-cdn.com/v4/letter/c/41988e/32.png) [@calioptrix](https://forums.sketchup.com/u/calioptrix)\
**Post date:** [January 26, 2021, 2:00am UTC](https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253/3 "2021-01-26T02:00:37Z")

</div>

Thanks so much for your help! This accomplishes my goal. You used intersect() instead of intersect\_with(). I don’t really understand the difference. The documentation is a bit fuzzy; it says intersect() “is used to compute the boolean intersection of two groups.” I interpreted this as meaning it would not change the geometry but instead would return some values.

---

<div class="post-metadata">

**Author:** ![DanRathbun](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/danrathbun/32/500_2.png) [@DanRathbun](https://forums.sketchup.com/u/DanRathbun)\
**Post date:** [January 26, 2021, 2:14am UTC](https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253/4 "2021-01-26T02:14:02Z")

</div>

> [@calioptrix](#):
>
> it says intersect() “is used to compute the boolean intersection of two groups.” I interpreted this as meaning it would not change the geometry but instead would return some values.

See …

> **[Boolean operations on polygons](https://en.wikipedia.org/wiki/Boolean_operations_on_polygons)**
>
> Boolean operations on polygons are a set of Boolean operations (AND, OR, NOT, XOR, ...) operating on one or more sets of polygons in computer graphics. These sets of operations are widely used in computer graphics, CAD, and in EDA (in integrated circuit physical design and verification software).
> Early algorithms for Boolean operations on polygons were based on the use of bitmaps. Using bitmaps in modeling polygon shapes has many drawbacks. One of the drawbacks is that the memory usage can be ve...

> **[Constructive solid geometry](https://en.wikipedia.org/wiki/Constructive_solid_geometry)**
>
> Constructive solid geometry (CSG; formerly called computational binary solid geometry) is a technique used in solid modeling. Constructive solid geometry allows a modeler to create a complex surface or object by using Boolean operators to combine simpler objects, potentially generating visually complex objects by combining a few primitive ones.
> In 3D computer graphics and CAD, CSG is often used in procedural modeling. CSG can also be performed on polygonal meshes, and may or may not be procedura...

… and a video …

[![](https://global.discourse-cdn.com/sketchup/original/3X/0/b/0b0a5b74c0b4c7f78697efd425db5da50cdc9478.jpeg "Boolean Operations in CAD & 3D Modelling - Basics (animation)") ](https://www.youtube.com/watch?v=HEMNv4mze3Q)

---

<div class="post-metadata">

**Author:** ![Neil\_Burkholder](https://avatars.discourse-cdn.com/v4/letter/n/f4b2a3/32.png) [@Neil\_Burkholder](https://forums.sketchup.com/u/Neil_Burkholder)\
**Post date:** [January 26, 2021, 12:12pm UTC](https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253/5 "2021-01-26T12:12:30Z")

</div>

> [@calioptrix](#):
>
> I don’t really understand the difference.

Here are the UI equivalents of the two methods.  
 ![image](https://global.discourse-cdn.com/sketchup/original/3X/7/f/7f00e9c4199e2b1ee7b9ef38d25e648e70762239.png)

 ![image](https://global.discourse-cdn.com/sketchup/original/3X/d/3/d3581d3093cd914112eb5eb8e2e039bd148f7d0f.png)

---

<div class="post-metadata">

**Author:** ![slbaumgartner](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/slbaumgartner/32/7302_2.png) [@slbaumgartner](https://forums.sketchup.com/u/slbaumgartner)\
**Post date:** [January 26, 2021, 3:29pm UTC](https://forums.sketchup.com/t/creating-decking-with-intersect-with/150253/6 "2021-01-26T15:29:37Z")

</div>

In the Ruby API documentation, [intersect\_with](https://ruby.sketchup.com/Sketchup/Entities.html#intersect_with-instance_method) is not explained very well, which can cause confusion. It has quite a bit more power and flexibility than Group#intersect. Here’s some discussion that might help you to understand how to use it.

There are two sets of Faces involved. The method will generate all of the Edges where a Face from the receiver of the method (the Entities collection on which you invoke the method) intersects a Face from the Array of Entities passed as the final argument, “entities2”. The resulting new Edges are added to the argument “entities1” Entities collection. In my experience, the method may or may not also create all the Faces associated with the new Edges, so it is wise to follow up with find\_faces or similar to force their creation.

Like the Intersect Faces with… method in the GUI, the intersect\_with API method does not do any cleanup for you. If your intent is to mimic a Solid Tools operation that removes geometry, you will have to program that separately yourself.

Contrary to the documentation, the method never returns nil though it might raise an exception for incorrect arguments. It returns an Array containing any new Edges created. As noted, these Edges are actually added to entities1. Returning them lets you identify them without having to search entities1, a potentially error-prone task if entities1 was not previously empty. The Array will be empty if no intersection Edges were found.

The purpose of the two Transformation arguments is not explained well.

The first one (“transform1”) maps the coordinates of the receiver into the coordinates of the “entities2” objects. Note that this implies that all the objects in entities2 must be in the same coordinates else confusing errors will occur. However, making you provide this Transformation explicitly allows you to deal with situations in which neither the receiver nor entities2 are in the model’s global coordinates. You will have to concatenate step-by-step Transformations or their inverses in such cases to create what is required.

The second Transformation (“transform2”) maps the coordinates of “entities1” into the coordinates of entities2. This is used (actually its inverse) to convert the new Edges from the (implicit) coordinates of entities2 into the coordinates of entities1. Again, except in simple cases you will have to build this Transformation.

The “recurse” Boolean argument specifies whether Faces in nested objects in the receiver will be recursively included. It is all or nothing; there is no way to descend only part way into the nest. Nested objects in entities2 are always included, regardless of the value of recurse.

The “hidden” Boolean argument affects both the receiver and entities2. There is no way to specify them separately.
