How to calculate the real width of objects

In inkscape, it can be particullary hard to evaluate the real width of objects, such as square, rectangle or right triangle, when a stroke width is applied.

The parameters

Let’s try to make it a little more clear:

  • s is the stroke width you set up in the “Fill and Stroke” box
  • w_{ini} is the initial width you can set up in the “Transform” box (“Scale” tab) (Be carefull to apply until your object had the correct width and height
  • w_{ext} is the total width of your object, taking into account the stroke width s.
  • w_{int} is the width of the internal part of your object (the one wich is colored by the Fill function in the “Fill and Stroke” box

The tools allows you to set up s and w_{ini}, but if you want to scale and place your object precisely, you will want to know w_{ext} and w_{int}.

So, we need equations that link:

  • w_{ext} to s and w_{ini} (Equation 1)
  • w_{int} to s and w_{ini} (Equation 2)

The equations

Equation 1:
Equation 2:

An exemple of application

In a specific project of mine, I had to put 2 identical right triangles in the height with this specific conditions:

  • the bottom stroke of the triangle in the bottom should be visible inside the document and at the very bottom of it
  • the top stroke of the triangle in the top should be out of the document and the top extremity of the “Fill” area should be at the very top of the document
  • Moreover the outer limit of the stroke of the bottom triangle should arrive precisely at bottom right corner of the document

I summarize this conditions in the following equations:

  • Equation 3: 2w_{int}+s=MAX where MAX is the width of the document (in this cas, the width was equal to the eight)
  • Equation 4: w_{ext}=MAX

When replacing w_{int} from Equation 2 with its value in Equation 3, and replacing w_{ext} from Equation 1 with its value in Equation 4, we obtained a 2 equations system:

  • Equation 5: w_{ext}=\frac{MAX-s}{2}+2s+\frac{s}{2^{1/2}}
  • Equation 6: w_{ext}=MAX-\frac{s}{2^{1/2}}

Solving this system lead to s=\frac{MAX*2^{1/2}}{4+(3*2^{1/2})} and allowed me obtain a unique pair value (w_{real}, s). By appling this object width and stroke width to my objects, I ended up with perfectly placed and scaled objects.

Thank you maths.

Posted in Software Tagged with: , , , , , ,

Leave a Reply