Avoid original rescaling after use of Geom::Transformation


#1

This is possible? How?

I am using some transformations ( like rotation and axe ) but my group resize for original size.
I need maintain the same size after scaling and before to use Geom::Transformation.

mod = Sketchup.active_model # Open model
sel = mod.selection # Current selection

# Get dimensions from the original bounding box

bb1 = sel[0].local_bounds

puts d1 = bb1.depth.round(5)
puts w1 = bb1.width.round(5)
puts h1 = bb1.height.round(5)

# Get dimensions from the scaloned bounding box

group2 = sel[0]
bb2    = Geom::BoundingBox.new
bb2.add(group2.bounds)
puts "..."
puts d2 = bb2.depth.round(5)
puts w2 = bb2.width.round(5)
puts h2 = bb2.height.round(5)
puts "..."
o = [d1, w1, h1] # original bounding box
o = o
s = [d2, w2, h2] # scaloned bounding box
s = s
w = o.include?(0)
if w == true
  w = o.index(0)
  o[w] = 1
  w = s.index(0)
  s[w] = 1
end
print o
puts "..."
print s
puts "..."
r = o.zip(s).map {|i, j| i/j}
puts "the factor is #{r}"
t = Geom::Transformation.scaling(ORIGIN, r)
sel[0].transform!(t)

Unfortunally i could not resize again.

EDITED:

t = Geom::Transformation.new(ORIGIN, r)

to

t = Geom::Transformation.scaling(ORIGIN, r)


#3

I don’t understand what your code snippet is trying to accomplish. The Transformation#new version you invoke places the z axis along the Vector3d direction defined by the r Array, which contains the scale factors of the Group for the three model axes. Sorry, but I fail to see what that is for…

I also don’t know what you mean by “i could not resize again”. When I tried this snippet, I could continue to resize the Group afterward.


#4

Hi @slbaumgartner

I edited the original post and includes an image for illustration.

I made this code to fix that but would like avoid the resizing for original size after the transformation.
Without this code.

Another question. How to tell for Ruby to consider the local axes instead the global axes?


#5

It is happening because
r=o.zip(s)
interleaves the two arrays as
[[d1,d2], [w1,w2], [h1,h2]]
and the map method therefore calculates
[d1/d2, w1/w2, h1/h2].
(as an aside, since you have those values in hand, building Arrays and going through zip and map seems overly ornate compared to just doing the divisions)
These are the ratios that scale sel[0] approximately back to the original size (approximately because you rounded the values)! If you want to retain it as-scaled, why are you changing its scaling at all?

It isn’t clear to me whether you want to retain both the original scaled version and a copy at a new orientation or location. But if so, you should be using a Component, not a Group. Each ComponentInstance has its own Transformation with respect to the ComponentDefinition, independent of the other instances of that ComponentDefinition.