<p>It helps to understand the different aspects of dimensions, so you can use the terminology correctly.  This will help you define your variables in OpenSCAD with correct names.  (Tolerance is the wrong term to use.)  And once you have correct names, you'll understand how to specify the dimensions in OpenSCAD.</p>

<ul>
<li><em>Tolerance</em> is the amount of random deviation or variation permitted for a given dimension.</li>
<li><em>Allowance</em> is a planned difference between a nominal or reference value and an exact value.  </li>
<li><em>Clearance</em> is the intentional space between two parts.</li>
<li><em>Interference</em> is the intentional overlap between two parts. </li>
</ul>

<p>Two other terms </p>

<ul>
<li><em>Accuracy</em> is the maximum dimensional variation between parts.  A machine cannot produce parts with a tighter tolerance than its accuracy.</li>
<li><em>Precision</em> is the size of the steps your machine is capable of. It is often confused with accuracy.</li>
</ul>

<p>In your case you need to define the <em>allowance</em> in order to create the <em>clearance</em> you desire.</p>

<p>To design your 5&nbsp;mm pin and 5&nbsp;mm hole, you need to understand your machine's accuracy.  The printer could print the pin larger than 5&nbsp;mm or smaller than 5&nbsp;mm.  Or it could print the hole larger than 5&nbsp;mm or smaller than 5&nbsp;mm.  You'll need to print some pins and holes and measure the differences between what you defined and what you printed.  The difference between the largest and smallest measurements you take is your machine's accuracy.  And be sure to check the accuracy in your X, Y, and Z dimensions; your printer might have a difference between them that would impact the roundness of the parts.  </p>

<p>Let's say that your printer's measured accuracy is &plusmn;&nbsp;0.2&nbsp;mm.</p>

<p>Then, we move to clearance.  What is the minimum gap between parts you are looking for, and what is the maximum you can accept?</p>

<p>Let's say you want a clearance of at least 0.2&nbsp;mm between the pin and hole, but no more than 1.0&nbsp;mm.  Since your accuracy is &plusmn; 0.2&nbsp;mm, your pin will be 5.0&nbsp;&plusmn;&nbsp;0.2&nbsp;mm, so the hole must therefore be 5.6&nbsp;mm&nbsp;&plusmn;&nbsp;0.2&nbsp;mm.  The minimum tolerance condition would be an minimum sized hole (5.4&nbsp;mm) and a maximum sized pin (5.2&nbsp;mm); the maximum tolerance would be a maximum sized hole (5.8&nbsp;mm) and a minimum sized pin (4.8&nbsp;mm).</p>

<p>Note that a clearance of 1.0&nbsp;mm might be too sloppy for your application.  You might think to tighten the tolerances to 0.05&nbsp;mm in order to reduce the clearance.  But if your printer can't produce a part that meets your specified tolerances, you would need to find a different way to manufacture or finish the parts.</p>

CC BY-SA 3.0
2017-12-31T02:13:42.093Z
Thank you for providing me with the proper English vocabulary to communicate with other designers effectively! I updated my question accordingly.  However my question is specifically about **organising OpenSCAD code**, not about the theory and practice of allowances (which I already understood, albeit ignoring the proper English terms). :)  May I suggest that you create a wiki-style question (option when you edit the question) like "What are the differences between allowance and tolerance?" and move your text there?  This is very useful information, but it isn't an answer to my question, alas!
mac
CC BY-SA 3.0
2017-12-31T02:15:44.000Z
...and of course I'd be the first to upvote that... just let me know in the comments if you get around to do it! :)
mac
CC BY-SA 4.0
2022-08-09T15:00:40.967Z
@mac , it took a while but https://3dprinting.stackexchange.com/questions/19747/what-is-the-difference-between-allowance-and-tolerance/19748#19748
John Deters
CC BY-SA 4.0
2017-12-29T06:14:14.360Z
2019-05-01T14:52:54.463Z
2019-05-01T14:52:54.463Z
John Deters
<p>I’m not aware of a standard in Openscad but I can share what I have done in the past.</p>

<pre><code>cutoutActualDiameter = 10;
cutoutDiameterClearance = 0.1;
cutoutDiameter = cutoutActualDiameter + cutoutDiameterClearance;
</code></pre>

<p>I know this is verbose but unfortunately in my experience that is a necessity if you want your code to be maintainable in Openscad. The benefit of this is that up until you need any clearance added you can just use the variable <code>cutoutDiameter</code>and then if and when you do need clearance added you can rename that variable and you don’t have to change any of the code where the variable is consumed.</p>

<p>Would love to hear how others manage this though.</p>

CC BY-SA 3.0
2018-02-04T08:33:01.917Z
So, are you saying that instead of using a variable for all allowances you create an ad-hoc variable for each and every dimension in your part?  If not, can you clarify what is the difference between your approach and the one described in the question itself?  Thanks! :)
mac
CC BY-SA 3.0
2018-02-04T12:26:56.223Z
@mac that’s correct. You could still use this pattern with a more global tolerance variable and you would have the flexibility to use it where you can or to be as granular as you need. Some things may need a tight fit. Others should have some give.
Nick Dancer
CC BY-SA 3.0
2018-02-04T07:45:58.077Z
2018-02-04T07:45:58.077Z
Nick Dancer
<p>Well, the tolerances will depend on material to be used for fabrication of the required part and also where the part will go and fit. Remember the all parts need some clearance to fit properly.</p>

<p>Few years ago (10 years) I was working as Quality Engineer and some Design Engineers were complaining about a Dupont pin was not fitting on the PCB so they told me that I need to force the PCB manufacturing to increase the holes to the higher tolerance. Which I had to ask him firstly the pin size and told me 0.70 mm and hole size 0.80 and maximum 0.90 
 - hmmm and maximum size of the pin? I asked, and they told me proudly 0.78mm so the part will fit perfectly.
 - Oh, so one square pin of 0.78mm will fit on one hole of 0.9mm, but what about the diagonal dimension? if the pin on the higher dimension is close to 1.2mm.</p>

<p>Imagine what happened later, engineering changes and modifying other designs due improper tolerances. pro-engineer software was unable to calculate what the designers needed.</p>

<p>Material has shrinkage, warpage, and other conditions that is needed to know like malleability and hardness and some of this data is on the specification material or the part specification.</p>

CC BY-SA 3.0
2018-01-02T12:31:29.890Z
This does not answer the question in any way.
tjb1
CC BY-SA 3.0
2018-01-02T22:03:05.630Z
@tjb1 This make you think about considering tolerances even if you are using the best cad software.
Fernando Baltazar
CC BY-SA 3.0
2018-01-03T00:44:39.733Z
The question is asking how to apply tolerances inside of OpenSCAD when coding, not how tolerances apply to a real part.
tjb1
CC BY-SA 3.0
2018-01-03T05:21:13.503Z
@tjb1 So, the user will never plan to use in real parts?
Fernando Baltazar
CC BY-SA 3.0
2018-01-03T05:30:40.403Z
@tjb1 Now the question has changed to allowance instead tolerances.
Fernando Baltazar
CC BY-SA 3.0
2018-01-03T12:04:29.607Z
Regardless if it's tolerances or allowances, the question is about how to apply them in the code inside OpenSCAD that is generating the model, see the bullet points of the question.  StackExchange is not a forum and your answer is largely a story about a previous job, but not an answer to the question.
tjb1
CC BY-SA 3.0
2018-01-03T21:42:52.900Z
@tjb1 Certainly my answer is about a tolerances wrong applied due lack of knowledge whom were believing in a software to do his job. So my answer is to not let the job to the sofware or there will be problems on final product. Forum? I´m away from them and i´m not pretend to do or participate on any. I prefer to say "stories" in companies where I have to lead to improve his process (quality management); there are people who don't like the stories, they have to quit the company because they can't have a good approaching to the company goals.
Fernando Baltazar
CC BY-SA 3.0
2017-12-27T07:25:53.167Z
2017-12-27T07:25:53.167Z
Fernando Baltazar
<p>I'm designing a few mechanisms with OpenSCAD, and one of the parameters that need adjustment between printers/filaments is allowances between pieces that need to be assembled together (for example, if I want a "5&nbsp;mm diameter pin" to fasten two pieces together, how much larger than 5&nbsp;mm will the holes / how much smaller than 5&nbsp;mm will the pin need to be).</p>

<p>Currently I approach the problem by setting a global variable <code>allowance</code> and manually using it in the code, something like:</p>

<pre><code>module pin(radius) {
    cylinder(r = radius + allowance)
}

module hole(radius) {
    cylinder(r = radius - allowance)
}
</code></pre>

<p>I have no real world experience with design though, so I wonder if there are common or <strong>coding</strong> best practices to account for allowances when designing parts like for example:</p>

<ul>
<li>specific modules to be used,</li>
<li>conventional names for variables</li>
<li>specific techniques to be used (scaling? vectors?)</li>
<li>conventions (like only use tolerances on the fastener, not the fastened object)</li>
<li>...?</li>
</ul>

<p>To clarify: I'm not looking on advice on how to plan the dimensions of my designs.  Rather, I am looking for advice on how to organise the OpenSCAD code generating them.</p>

CC BY-SA 3.0
2017-12-20T08:05:29.550Z
I suspect that OpenSCAD is too niche to have such conventions. What you are doing is very similar to my own practices.
Mick
CC BY-SA 4.0
2022-08-08T19:04:53.560Z
You can also add clearance using vector math, something like this `[ l, w, h ] + clearance * [1, 1, 1]` for objects like cubes and the like. And the function `resize()` is quite useful.
Evgeny Zislis
<3d-design><openscad><knowledgebase>
Are there any "best" or at least "common" practices to handle allowances in OpenSCAD code?
mac
# Are there any "best" or at least "common" practices to handle allowances in OpenSCAD code?

(Asked by: username_0 on 2017-12-20)

I'm designing a few mechanisms with OpenSCAD, and one of the parameters that need adjustment between printers/filaments is allowances between pieces that need to be assembled together (for example, if I want a "5 mm diameter pin" to fasten two pieces together, how much larger than 5 mm will the holes / how much smaller than 5 mm will the pin need to be).
Currently I approach the problem by setting a global variable allowance and manually using it in the code, something like:
module pin(radius) {
    cylinder(r = radius + allowance)
}

module hole(radius) {
    cylinder(r = radius - allowance)
}

I have no real world experience with design though, so I wonder if there are common or coding best practices to account for allowances when designing parts like for example:

specific modules to be used,
conventional names for variables
specific techniques to be used (scaling? vectors?)
conventions (like only use tolerances on the fastener, not the fastened object)
...?

To clarify: I'm not looking on advice on how to plan the dimensions of my designs.  Rather, I am looking for advice on how to organise the OpenSCAD code generating them.

**Tags:** 3d-design, openscad, knowledgebase
> **Comments:**
> **username_1**: I suspect that OpenSCAD is too niche to have such conventions. What you are doing is very similar to my own practices.  
> **username_2**: You can also add clearance using vector math, something like this `[ l, w, h ] + clearance * [1, 1, 1]` for objects like cubes and the like. And the function `resize()` is quite useful.  

---

## 3 answers

### Answer by username_3 on 2017-12-29. Score: 7

It helps to understand the different aspects of dimensions, so you can use the terminology correctly. This will help you define your variables in OpenSCAD with correct names. (Tolerance is the wrong term to use.) And once you have correct names, you'll understand how to specify the dimensions in OpenSCAD.

* *Tolerance* is the amount of random deviation or variation permitted for a given dimension.
* *Allowance* is a planned difference between a nominal or reference value and an exact value.
* *Clearance* is the intentional space between two parts.
* *Interference* is the intentional overlap between two parts.

Two other terms

* *Accuracy* is the maximum dimensional variation between parts. A machine cannot produce parts with a tighter tolerance than its accuracy.
* *Precision* is the size of the steps your machine is capable of. It is often confused with accuracy.

In your case you need to define the *allowance* in order to create the *clearance* you desire.

To design your 5 mm pin and 5 mm hole, you need to understand your machine's accuracy. The printer could print the pin larger than 5 mm or smaller than 5 mm. Or it could print the hole larger than 5 mm or smaller than 5 mm. You'll need to print some pins and holes and measure the differences between what you defined and what you printed. The difference between the largest and smallest measurements you take is your machine's accuracy. And be sure to check the accuracy in your X, Y, and Z dimensions; your printer might have a difference between them that would impact the roundness of the parts.

Let's say that your printer's measured accuracy is ± 0.2 mm.

Then, we move to clearance. What is the minimum gap between parts you are looking for, and what is the maximum you can accept?

Let's say you want a clearance of at least 0.2 mm between the pin and hole, but no more than 1.0 mm. Since your accuracy is ± 0.2 mm, your pin will be 5.0 ± 0.2 mm, so the hole must therefore be 5.6 mm ± 0.2 mm. The minimum tolerance condition would be an minimum sized hole (5.4 mm) and a maximum sized pin (5.2 mm); the maximum tolerance would be a maximum sized hole (5.8 mm) and a minimum sized pin (4.8 mm).

Note that a clearance of 1.0 mm might be too sloppy for your application. You might think to tighten the tolerances to 0.05 mm in order to reduce the clearance. But if your printer can't produce a part that meets your specified tolerances, you would need to find a different way to manufacture or finish the parts.

> **Comments:**
> **username_0**: Thank you for providing me with the proper English vocabulary to communicate with other designers effectively! I updated my question accordingly.  However my question is specifically about **organising OpenSCAD code**, not about the theory and practice of allowances (which I already understood, albeit ignoring the proper English terms). :)  May I suggest that you create a wiki-style question (option when you edit the question) like "What are the differences between allowance and tolerance?" and move your text there?  This is very useful information, but it isn't an answer to my question, alas!  
> **username_0**: ...and of course I'd be the first to upvote that... just let me know in the comments if you get around to do it! :)  
> **username_3**: @mac , it took a while but https://3dprinting.stackexchange.com/questions/19747/what-is-the-difference-between-allowance-and-tolerance/19748#19748  

---

### Answer by username_4 on 2018-02-04. Score: 2

I’m not aware of a standard in Openscad but I can share what I have done in the past.
cutoutActualDiameter = 10;
cutoutDiameterClearance = 0.1;
cutoutDiameter = cutoutActualDiameter + cutoutDiameterClearance;

I know this is verbose but unfortunately in my experience that is a necessity if you want your code to be maintainable in Openscad. The benefit of this is that up until you need any clearance added you can just use the variable cutoutDiameterand then if and when you do need clearance added you can rename that variable and you don’t have to change any of the code where the variable is consumed.
Would love to hear how others manage this though.

> **Comments:**
> **username_0**: So, are you saying that instead of using a variable for all allowances you create an ad-hoc variable for each and every dimension in your part?  If not, can you clarify what is the difference between your approach and the one described in the question itself?  Thanks! :)  
> **username_4**: @mac that’s correct. You could still use this pattern with a more global tolerance variable and you would have the flexibility to use it where you can or to be as granular as you need. Some things may need a tight fit. Others should have some give.  

---

### Answer by username_5 on 2017-12-27. Score: -2

Well, the tolerances will depend on material to be used for fabrication of the required part and also where the part will go and fit. Remember the all parts need some clearance to fit properly.

Few years ago (10 years) I was working as Quality Engineer and some Design Engineers were complaining about a Dupont pin was not fitting on the PCB so they told me that I need to force the PCB manufacturing to increase the holes to the higher tolerance. Which I had to ask him firstly the pin size and told me 0.70 mm and hole size 0.80 and maximum 0.90
- hmmm and maximum size of the pin? I asked, and they told me proudly 0.78mm so the part will fit perfectly.
- Oh, so one square pin of 0.78mm will fit on one hole of 0.9mm, but what about the diagonal dimension? if the pin on the higher dimension is close to 1.2mm.

Imagine what happened later, engineering changes and modifying other designs due improper tolerances. pro-engineer software was unable to calculate what the designers needed.

Material has shrinkage, warpage, and other conditions that is needed to know like malleability and hardness and some of this data is on the specification material or the part specification.

> **Comments:**
> **username_6**: This does not answer the question in any way.  
> **username_5**: @tjb1 This make you think about considering tolerances even if you are using the best cad software.  
> **username_6**: The question is asking how to apply tolerances inside of OpenSCAD when coding, not how tolerances apply to a real part.  
> **username_5**: @tjb1 So, the user will never plan to use in real parts?  
> **username_5**: @tjb1 Now the question has changed to allowance instead tolerances.  
> **username_6**: Regardless if it's tolerances or allowances, the question is about how to apply them in the code inside OpenSCAD that is generating the model, see the bullet points of the question.  StackExchange is not a forum and your answer is largely a story about a previous job, but not an answer to the question.  
> **username_5**: @tjb1 Certainly my answer is about a tolerances wrong applied due lack of knowledge whom were believing in a software to do his job. So my answer is to not let the job to the sofware or there will be problems on final product. Forum? I´m away from them and i´m not pretend to do or participate on any. I prefer to say "stories" in companies where I have to lead to improve his process (quality management); there are people who don't like the stories, they have to quit the company because they can't have a good approaching to the company goals.  

---

