# Sketchup: Constructing Triangle with Ruby

**URL:** <https://www.ruby-forum.com/t/sketchup-constructing-triangle-with-ruby/127349>\
**Category:** Ruby\
**Created:** [January 28, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/sketchup-constructing-triangle-with-ruby/127349 "2008-01-28T15:12:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dfb087/32.png) [@eps](https://www.ruby-forum.com/u/eps)\
**Post date:** [January 28, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/sketchup-constructing-triangle-with-ruby/127349/1 "2008-01-28T15:12:04Z")

</div>

Hello,

i’m constructing triangles with ruby and try to plot them within  
Sketchup. In most cases, this works. But sometimes, an error occurs:  
“Points are not planar”, which is quite strange for a triangle…

```
model = Sketchup.active_model
entities = model.active_entities
k = 0
for i in 1..3 do
    x = arr[k]
    y = arr[k+1]
    z = arr[k+2]

    pts << Geom::Point3d.new([x,y,z])

    k += 3
end

pts << pts.first()

begin
face = entities.add_face(pts)
rescue
puts $!.message
puts pts
end

```

arr is an array with the triangle coordinates (the coordinates come from  
an external data source, but thats not the problem)

An example output for an error is

Points are not planar  
(0,08255m, 0,003858m, 0,11049m)  
(0,083007m, 0,004218m, 0,11049m)  
(0,082855m, 0,004111m, 0,11049m)  
(0,08255m, 0,003858m, 0,11049m)

The last and the first point are the same, but thats correct (a face is  
constructed by a closed line).

o you have any ideas where I can find the error?

---

<div class="post-metadata">

**Author:** ![eps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dfb087/32.png) [@eps](https://www.ruby-forum.com/u/eps)\
**Post date:** [January 30, 2008, 2:32pm UTC](https://www.ruby-forum.com/t/sketchup-constructing-triangle-with-ruby/127349/2 "2008-01-30T14:32:36Z")

</div>

On Jan 28, 2008 9:11 AM, Eps I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> x = arr[k]
> begin
> 
> ```
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

My wild guess:  
The first and last points may differ as they are built out of floating  
point numbers.  
Try integers to represent the points, at least , the first and the last.

Prasad

---

<div class="post-metadata">

**Author:** ![eps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dfb087/32.png) [@eps](https://www.ruby-forum.com/u/eps)\
**Post date:** [January 31, 2008, 2:37pm UTC](https://www.ruby-forum.com/t/sketchup-constructing-triangle-with-ruby/127349/3 "2008-01-31T14:37:39Z")

</div>

G.Durga P. wrote:

> My wild guess:  
> The first and last points may differ as they are built out of floating  
> point numbers.  
> Try integers to represent the points, at least , the first and the last.
> 
> Prasad

Well… I don’t think so. The first and last point are exakly the same,  
bit by bit, as you can see here:

```
pts << pts.first() # adding last point

```

But thanks anyway…

---

<div class="post-metadata">

**Author:** ![eps](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/dfb087/32.png) [@eps](https://www.ruby-forum.com/u/eps)\
**Post date:** [September 3, 2008, 11:27am UTC](https://www.ruby-forum.com/t/sketchup-constructing-triangle-with-ruby/127349/4 "2008-09-03T11:27:02Z")

</div>

Eps I. wrote:

> G.Durga P. wrote:
> 
> > My wild guess:  
> > The first and last points may differ as they are built out of floating  
> > point numbers.  
> > Try integers to represent the points, at least , the first and the last.
> > 
> > Prasad
> 
> Well… I don’t think so. The first and last point are exakly the same,  
> bit by bit, as you can see here:
> 
> ```
> pts << pts.first() # adding last point
> 
> ```
> 
> But thanks anyway…

If you want a 3 sided shape, pass 3 points (AKA vertices) to  
entities.add\_face, not 4.

Todd

(Do I get the old post resurrection award today?)
