Tranformation

Sketchup.active_model.selection[0].transformation * any_point
what is the meaning of the above line and what will happen with the selection???

Sketchup
Sketchup.active_model
Sketchup.active_model.selection[0] the first element from the selection array
.transformation or .transformation depends what is the above mentioned element
* matrix multiplication
any_point : most probably any Geom::Point3d (must have been defined somewhere else in the code)

So the code will return a new Geom::Point3d based on the selected component instance or group transformation using matrix multiplication.


Nothing.

Sorry, no, it will return a new Geom::Transformation instance that does translation.

Strange…

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


Edit:
In this case the doc is right:
https://ruby.sketchup.com/Geom/Transformation.html#*-instance_method

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.)

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”.

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 )

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

1 Like

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