Problem using expressions/functions

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Problem using expressions/functions

Post by onekk »

MrGadget49 wrote: Mon Nov 28, 2022 5:29 pm ...
Yes the point is exactly this.

Many times the "main" problem is documentation.

(I've not your experience, but as I've started to program with a Commodore 64 when I was 16yo, we could be considered "old generation" programmers, where you have to read a multipage manual to start to use things.)

Please don't give up and maybe bring this problem with maybe your proposed solution in "Open Discussion" or "Developer forum", probably opening a "clear topic" about "expressions and units" would be useful.

I've had a proof when I've opened a topic about something and now it is became a very interesting discussion and some "clever people" are pointing put the problem and hopefully find a solution. Sadly the discussion has gone beyond my knowledge after some posts when the discussion was about "internals and algorithms" :lol:.

But if this will improve FreeCAD I will be happy to have "started things".

Many times people came here only to complain, so having a "plain discussion" with people is difficult these times.

I'm also happy to make some discussion with users that will not end in ruvid sentences.

It is difficult as many of us are not "native English speakers" and probably we have not a "very educated" way to say things, so some "highly educated" peoples are hurt by our ruvid sentences, even if they are not intentional. (not every time sometimes they are very studied :lol: ).

I stop here, as I will be guilty to do "too Off Topic" discussions.

Kind Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Problem using expressions/functions

Post by GeneFC »

MrGadget49 wrote: Mon Nov 28, 2022 5:29 pm At this point I'm just grateful to know how it works
As a user of Inferial units I discovered this behavior a long time ago.

Yes, a warning in the wiki might be useful (but probably seldom read), and fully automatic correct behavior would be great (not gonna happen any time soon.)

For the most part the use of non-metric units works quite well. Linear functions of various types are computed correctly. The glaring exception is the computation of non-linear functions, as you have discovered. The problem is that the "correct" numerical results are different depending on the unit system.

For a parametric modeler such as FreeCAD, it seems very dangerous to directly support different numerical results depending on the unit system. Therefore, if the user needs such non-linear functions, it is probably best that the user is directly responsible for making the conversions.

My approach is to strictly avoid non-linear functions.

Gene
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Re: Problem using expressions/functions

Post by MrGadget49 »

GeneFC wrote: Mon Nov 28, 2022 10:27 pm ...
Yup I agree!

Jody
chrisb
Veteran
Posts: 53921
Joined: Tue Mar 17, 2015 9:14 am

Re: Problem using expressions/functions

Post by chrisb »

GeneFC wrote: Mon Nov 28, 2022 10:27 pm As a user of Inferial units
:lol: funny typo!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: Problem using expressions/functions

Post by adrianinsaval »

I choose to believe that the typo there is writing ri instead of rn ;)
MrGadget49 wrote: Sun Nov 27, 2022 6:18 pm but It would make more sense to me, if it just did the calculations based on what is set as the default units instead of mm.
I don't think this is possible because expressions must use a consistent unit system regardless of user setting, otherwise when I open your model in my computer configured to use mm the result would be different than for you, potentially breaking the model or at the very least changing it.
chrisb
Veteran
Posts: 53921
Joined: Tue Mar 17, 2015 9:14 am

Re: Problem using expressions/functions

Post by chrisb »

We europeans are trained to think that imperial is infernal.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Problem using expressions/functions

Post by GeneFC »

Close, but try inferior. :lol: :lol:

Gene
chrisb
Veteran
Posts: 53921
Joined: Tue Mar 17, 2015 9:14 am

Re: Problem using expressions/functions

Post by chrisb »

GeneFC wrote: Tue Nov 29, 2022 2:26 pm Close, but try inferior. :lol: :lol:
:lol: :lol:

I have learned that people being socialized with imperials tend to think in fractions than in decimals. While we say that 1 mile is 1.8 km long, the "imperialists" say something like "there are 9 km in 5 miles.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Re: Problem using expressions/functions

Post by MrGadget49 »

chrisb wrote: Tue Nov 29, 2022 3:19 pm I have learned that people being socialized with imperials tend to think in fractions than in decimals. While we say that 1 mile is 1.8 km long, the "imperialists" say something like "there are 9 km in 5 miles.
I don't really mind working in either unit. I just try use whichever works best for the job at hand. In this case, I'm using lumber milled in America to inch dimensions.

You are rite about us thinking in fractions! 1/3 of a yard is 1 foot. 1/3 of a foot is 4 inches. What's 1/3 of a meter? 0.33333 of a meter or 304.8mm. To me, it's easier to pull out my imperial ruler and find the 1 foot marks.

That being said, I do use metric as much as I can. I don't really think either one is better than the other. They're just different.


Jody
MrGadget49
Posts: 27
Joined: Mon Oct 03, 2022 6:31 am

Re: Problem using expressions/functions

Post by MrGadget49 »

adrianinsaval wrote: Tue Nov 29, 2022 11:42 am I don't think this is possible because expressions must use a consistent unit system regardless of user setting, otherwise when I open your model in my computer configured to use mm the result would be different than for you, potentially breaking the model or at the very least changing it.
That is some food for thought....


Based on the method I described above where the value is calculated in inches or just raw numbers I don't think it would be a huge impact.

If i used the expression 'trunc(2.395in) and it calculated the answer to be 2.00 inches (because the input units were inches) and then you opened it on your system with the defaults set to mm, it would convert 2.00 inches to 50.8mm. Which would be exactly what I intended.

What it's doing now, is converting 2.395in to 60.833mm and then truncating that to 60. I would get 2.3622 inches. On your system, you will get 60mm. It's not even what I intended on my system, so it would probably never get to your system.

So, we do the trunc(2.395in / 1in) to trick it into giving us the raw # 2.0 then we multiply that by 1in to give us 2in and on your system we get 50.8mm.

It works, but it just seems kind of complicated compared to having a trunc function that gives you the output value in the same units as the input value.


The problem is, how to change it without breaking every model that's ever used one of these functions. Things have to be backwards compatible. There's two ways I've thought of that might work. one is just create a new function name that no one has used yet like say truncb(). The other is to add a new extra argument to the function where if present it would work the new way, if missing it work still work the old way. existing code wouldn't have the argument so nothing would break.

Jody
Post Reply