# Calculating for the scale factor

**URL:** <https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817>\
**Category:** Ruby API\
**Tags:** advice\
**Created:** [December 11, 2021, 11:01am UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817 "2021-12-11T11:01:05Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcosyu](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@marcosyu](https://forums.sketchup.com/u/marcosyu)\
**Post date:** [December 11, 2021, 11:01am UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/1 "2021-12-11T11:01:05Z")

</div>

I’m trying to use the transform command to reduce my shape. To give an example of what i want to accomplish, Lets say I have shape 1 (no face) and would like to scale it down to be like shape 2

 ![image_2021-12-11_185840](https://global.discourse-cdn.com/sketchup/original/3X/4/a/4a893ccc8f87d05fc8a34d380d96b7c0056c9f9a.png)

One thing I’ve tried is calculate for the area of both of the shape then divide them like this  
smaller polygon area / larger polygon area but if I use it to scale it can’t get it to match shape 2  
I understand that the scale that is needed for the transformation is the “global scale factor” but where do i get it from?

---

<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:** [December 11, 2021, 1:58pm UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/2 "2021-12-11T13:58:50Z")

</div>

Are the shapes groups or component instances ?

If yes, then see these posts for getting the scales of instances:  
[How to check if 2 transformation are same? - #4 by DanRathbun](https://forums.sketchup.com/t/how-to-check-if-2-transformation-are-same/168887/4)  
… or …  
[Face#area weird behavior - #6 by Aerilius](https://forums.sketchup.com/t/face-area-weird-behavior/14500/6)

If not, get the scale by using the edges.

```ruby
scale = edge1_of_shape2 / edge1_of_shape1

```

---

<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:** [December 11, 2021, 2:30pm UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/3 "2021-12-11T14:30:38Z")

</div>

Area is a quadratic quantity, whereas the scale is linear. So you need to use the square root of the ratio of the areas. Math.sqrt(150.0/337.5) = 0.66666666

---

<div class="post-metadata">

**Author:** ![marcosyu](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@marcosyu](https://forums.sketchup.com/u/marcosyu)\
**Post date:** [December 11, 2021, 2:46pm UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/4 "2021-12-11T14:46:03Z")

</div>

Actually the shapes are just an array points (Geom::Point3D) . So I cant reference it back to edges

---

<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:** [December 11, 2021, 5:41pm UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/5 "2021-12-11T17:41:00Z")

</div>

You are dribble-feeding us details that affect the answer!

If all you have are points and you know how to pick corresponding pairs of points in the two shapes, you can use

```ruby
point1.distance(point2)

```

to get how far apart they are. The ratio of distances will be the scale factor.

---

<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:** [December 11, 2021, 7:49pm UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/6 "2021-12-11T19:49:38Z")

</div>

> [@marcosyu](#):
>
> Actually the shapes are just an array points (Geom::Point3D)

FYI: See [`Geom::Point3d#transform!()`](https://ruby.sketchup.com/Geom/Point3d.html#transform!-instance_method)

---

<div class="post-metadata">

**Author:** ![marcosyu](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@marcosyu](https://forums.sketchup.com/u/marcosyu)\
**Post date:** [December 12, 2021, 12:33am UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/7 "2021-12-12T00:33:09Z")

</div>

Sorry if I missed some details just to be clear here’s a sample code that im using to generate the scaled down face

```auto
  def scale(original_pts, transformed_pts)
    scale_factor = calculate_scaling_factor(original_pts, transformed_pts) 
    # for now this is not returning the correct factor
    t = Geom::Transformation.new(scale_factor) 
    new_face = points.map{|pt|pt.transform(t) }
    Sketchup.active_model.entities.add_face(new_face)
  end
  # based on @slbaumgartner previous comment
  def calculate_scaling_factor(original_pts, transformed_pts)
    original_initial_length = original_pts[0].distance(original_pts[1])
    transformed_initial_length = transformed_pts[0].distance(transformed_pts[1])
    Math.sqrt((original_initial_length / transformed_initial_length).abs)  
  end

```

In this drawing I have a 15x15 inches box and i would like to generate or scale it down to 10x10 but the scaling still doesn’t get the exact dimension of 10x10. Based on the formula I would get a value of `0.816496580927726`

 ![scaling down 2](https://global.discourse-cdn.com/sketchup/original/3X/1/c/1c600e05c119c1113c8bb415f3b9c70a6b54b89a.jpeg)  
and to add I’ve tried moving the edges to a component just not to bump into the face that i created that has the same dimension of my original points and found out that I should get `~0.67` for the scale  
 ![image_2021-12-12_083743](https://global.discourse-cdn.com/sketchup/original/3X/e/e/eed7a5c0b134631da39b2d5ed04b4c1d87e26f1e.png)  
currently using a quadrilateral shape for now but the shape could be any polygon shaped points

---

<div class="post-metadata">

**Author:** ![marcosyu](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@marcosyu](https://forums.sketchup.com/u/marcosyu)\
**Post date:** [December 12, 2021, 12:34am UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/8 "2021-12-12T00:34:02Z")

</div>

Thanks already using it to transform all the points in the code. I think what im lacking now is how do i get the scaling factor that i should be using to generate the exact scale

---

<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:** [December 12, 2021, 12:55am UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/9 "2021-12-12T00:55:09Z")

</div>

You misunderstood me. You need a square root if you are comparing areas. If comparing distances you just need to divide.

---

<div class="post-metadata">

**Author:** ![marcosyu](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@marcosyu](https://forums.sketchup.com/u/marcosyu)\
**Post date:** [December 12, 2021, 2:40am UTC](https://forums.sketchup.com/t/calculating-for-the-scale-factor/183817/10 "2021-12-12T02:40:34Z")

</div>

Thanks! It returns the same shape now
