# Tranformation

**URL:** <https://forums.sketchup.com/t/tranformation/140181>\
**Category:** Ruby API\
**Tags:** sketchup\
**Created:** [October 24, 2020, 8:08am UTC](https://forums.sketchup.com/t/tranformation/140181 "2020-10-24T08:08:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwertyuiop](https://avatars.discourse-cdn.com/v4/letter/q/db5fbb/32.png) [@qwertyuiop](https://forums.sketchup.com/u/qwertyuiop)\
**Post date:** [October 24, 2020, 8:08am UTC](https://forums.sketchup.com/t/tranformation/140181/1 "2020-10-24T08:08:24Z")

</div>

Sketchup.active\_model.selection[0].transformation \* any\_point  
what is the meaning of the above line and what will happen with the selection???

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [October 24, 2020, 8:43am UTC](https://forums.sketchup.com/t/tranformation/140181/2 "2020-10-24T08:43:35Z")

</div>

> [@qwertyuiop](#):
>
> `Sketchup.active_model.selection[0].transformation * any_point`  
> what is the meaning of the above line…

[Sketchup](https://ruby.sketchup.com/Sketchup.html)  
[Sketchup.active\_model](https://ruby.sketchup.com/Sketchup.html#active_model-class_method)  
[Sketchup.active\_model.selection[0]](https://ruby.sketchup.com/Sketchup/Selection.html) the first element from the selection array  
[.transformation](https://ruby.sketchup.com/Sketchup/Group.html#transformation-instance_method) or [.transformation](https://ruby.sketchup.com/Sketchup/ComponentInstance.html#transformation-instance_method) depends what is the above mentioned element  
[\*](https://ruby.sketchup.com/Geom/Transformation.html#*-instance_method) matrix multiplication  
any\_point : most probably any [Geom::Point3d](https://ruby.sketchup.com/Geom/Point3d.html) (must have been defined somewhere else in the code)

So the code will return a new [Geom::Point3d](https://ruby.sketchup.com/Geom/Point3d.html) based on the selected component instance or group transformation using matrix multiplication.

* * *

> [@qwertyuiop](#):
>
> …what will happen with the selection?

Nothing.

---

<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:** [October 24, 2020, 5:20pm UTC](https://forums.sketchup.com/t/tranformation/140181/3 "2020-10-24T17:20:22Z")

</div>

> [@dezmo](#):
>
> So the code will return a new [Geom::Point3d](https://ruby.sketchup.com/Geom/Point3d.html) based on …

Sorry, no, it will return a new [`Geom::Transformation`](https://ruby.sketchup.com/Geom/Transformation.html) instance that does translation.

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [October 24, 2020, 5:38pm UTC](https://forums.sketchup.com/t/tranformation/140181/4 "2020-10-24T17:38:27Z")

</div>

Strange…

```ruby
def test_what(any_point)
  what_is_it = Sketchup.active_model.selection[0].transformation * any_point
  return what_is_it, what_is_it.class
end 
test_what(Geom::Point3d.new(2, 2, 2))

```

Return

> [Point3d(-3.72285, 10.9451, 3.14191), Geom::Point3d]

![image](https://global.discourse-cdn.com/sketchup/original/3X/6/8/6829a8e175acfbc4709d84f25fb6b536233c2623.png)

* * *

Edit:  
In this case the doc is right:  
[https://ruby.sketchup.com/Geom/Transformation.html#\*-instance\_method](https://ruby.sketchup.com/Geom/Transformation.html#*-instance_method)

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

---

<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:** [October 24, 2020, 9:13pm UTC](https://forums.sketchup.com/t/tranformation/140181/5 "2020-10-24T21:13:36Z")

</div>

**Okay, I will agree it is what the docs say.**

**But I think it is weird**.  
Normally we would expect **`point * transform`** to return a `point`,  
and the opposite to return a transform. (But the API is weird in many places.)

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [October 25, 2020, 8:55am UTC](https://forums.sketchup.com/t/tranformation/140181/6 "2020-10-25T08:55:43Z")

</div>

What you say sounds completely logical.  
Just for _my_ better understanding I did some more test.

I must agree that API is weird in many places. (Making it harder to learn.)

Unfortunately, my base knowledges are also incomplete to fully understand Ruby…and I can spend much less time understanding than I should

So, mostly I have to use the “trial and fail” method, to cover this incompleteness.

I do this now to analyze what you said: **`point * transform`** :  
I realized that there is no **`'#*'`** method for Point3d (at least not such a syntax), but I can use `‘#transform’ instead, than I get the same points in both “order”.  
There is no way to get transformation returned as we would expect “logically”.

```ruby
def test_what( any_point )
  t_mul_p = Sketchup.active_model.selection[0].transformation * any_point

  # There is no '*' method for Point3d, will give a NoMethodError
  # commented out
  # p_mul_t = any_point * Sketchup.active_model.selection[0].transformation
  
  # But we can use the '.transform' method
  p_tra_t = any_point.transform Sketchup.active_model.selection[0].transformation
    
  p "t_mul_p #{t_mul_p} #{t_mul_p.class} "
  p "p_tra_t #{p_tra_t} #{p_tra_t.class}"
  t_mul_p == p_tra_t
end 
test_what(Geom::Point3d.new(1, 1, 1))

```

Result:  
` "t_mul_p (25,4 mm, 278 mm, 25,4 mm) Geom::Point3d "`  
`"p_tra_t (25,4 mm, 278 mm, 25,4 mm) Geom::Point3d"`  
`true`

(This is what the currently selected group looks like:  
 ![image](https://global.discourse-cdn.com/sketchup/original/3X/8/4/84e853f02298b28fc7083f512ad6dc98ea9d805f.png) )

---

<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:** [October 25, 2020, 6:32pm UTC](https://forums.sketchup.com/t/tranformation/140181/7 "2020-10-25T18:32:22Z")

</div>

> [@dezmo](#):
>
> I realized that there is no **`'#*'`** method for Point3d …

I know. I was only making a hypothetical point about what is normally expected.

---

<div class="post-metadata">

**Author:** ![dezmo](https://sea2.discourse-cdn.com/sketchup/user_avatar/forums.sketchup.com/dezmo/32/51058_2.png) [@dezmo](https://forums.sketchup.com/u/dezmo)\
**Post date:** [October 25, 2020, 6:57pm UTC](https://forums.sketchup.com/t/tranformation/140181/8 "2020-10-25T18:57:17Z")

</div>

I know you know! 😉 But your comment makes me to learn too!
