Units, Formula editor and multiplication

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
peetervois
Posts: 6
Joined: Sun Oct 18, 2020 7:29 am

Units, Formula editor and multiplication

Post by peetervois »

This falls between possible bug or "know how to make the trick". I write it in this topic. I was trying to make some more (maybe advanced) part design tricks: I made 2 planes, defined a height with a sketch between the planes, and then I wanted to define a rotation of a object between the 2 planes for lofting. For clarity

SketchFirst - is one of the 2 planes
SketshHeight - is the plane that has a line on it and the length of the line defines the distance to ...
SketchSecond - is the second of the 2 planes

For that on my plane there is Constraints.a that defines this rotation angle and everything is calculated around it. On the SketchSecond I would like to make Formula for Constraints.a:

SketchFirst.Constraints.a + 0.3 * SketchHeight.Constraints.h

And this fails because the SketchFirst.Constraints.a is in "deg", the SketchHeight.Constraints.h is in "mm" and it seems I can not specify the units for 0.3 to be "deg/mm".

It might be possible that the units checking can be turned off (I do not know it yet) or is there something else that I am missing? Maybe a function that will define the unit for the result regardless what is the unit inside that function? I did not find any hints for existence of the function. The function would then be like:

SketchFirst.Constraints.a + deg( 0.3 * SketchHeight.Constraints.h )
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Units, Formula editor and multiplication

Post by chrisb »

peetervois wrote: Sun Oct 18, 2020 12:33 pm SketchFirst.Constraints.a + 0.3 * SketchHeight.Constraints.h

And this fails because the SketchFirst.Constraints.a is in "deg", the SketchHeight.Constraints.h is in "mm" and it seems I can not specify the units for 0.3 to be "deg/mm".

SketchFirst.Constraints.a + deg( 0.3 * SketchHeight.Constraints.h )
You cannot switch the units checker off. Without the file or a handmade doodle it is hard for me to understand your model. But what I can see is that you of course cannot add a length to an angle, what should the result be? And also you cannot convert a length to an angle. You may invoke some trigonometric function, see the Expressions page.

If you want to remove a unit, e.g. mm then you can divide the value by 1mm.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
peetervois
Posts: 6
Joined: Sun Oct 18, 2020 7:29 am

Re: Units, Formula editor and multiplication

Post by peetervois »

chrisb wrote: Sun Oct 18, 2020 1:23 pm
peetervois wrote: Sun Oct 18, 2020 12:33 pm SketchFirst.Constraints.a + 0.3 * SketchHeight.Constraints.h

And this fails because the SketchFirst.Constraints.a is in "deg", the SketchHeight.Constraints.h is in "mm" and it seems I can not specify the units for 0.3 to be "deg/mm".

SketchFirst.Constraints.a + deg( 0.3 * SketchHeight.Constraints.h )
You cannot switch the units checker off. Without the file or a handmade doodle it is hard for me to understand your model. But what I can see is that you of course cannot add a length to an angle, what should the result be? And also you cannot convert a length to an angle. You may invoke some trigonometric function, see the Expressions page.

If you want to remove a unit, e.g. mm then you can divide the value by 1mm.
Yes I can not add length to angle, but I can convert length to angle through conversion formula. One of the easiest conversion formula is multiplication y=a*c, where the conversion factor a has unit [angle * length^-1]. Since [angle * length^-1] * [length] === [angle]. The formula of-course depends on physics and finding that formula is where physics ends and mathematics starts.

I change the topic a very little, since I see the units system has probably very related issues. Maybe my issue is more like that the units system is unable to correctly figure out units of the constraints. I attached a picture that shows the error. I can not calculate atan(Constraints.h/Constraints.w) but I can calculate atan(2mm/3mm) I also have seen that the multiplication of units works in some explicit cases but fails when Constraints are used. (FreeCAD 0.18). The project is also added.
Attachments
contraintformulaunitissue.FCStd
(3.79 KiB) Downloaded 38 times
Screenshot_2020-10-26_15-35-44.png
Screenshot_2020-10-26_15-35-44.png (51.48 KiB) Viewed 2414 times
chrisb
Veteran
Posts: 54197
Joined: Tue Mar 17, 2015 9:14 am

Re: Units, Formula editor and multiplication

Post by chrisb »

Now I understand, and the problem comes from a completely different corner: Using the names "w" and "h" conflicts with some internal names. This may be already fixed, there is a pull request waiting to be merged.
Rename them to width and height and use atan(Constraints.height / Constraints.width) without issues.

In your special case I would recommend something completely different: Use a geometric solution by adding a point-on-line constraint placing the top point on the diagonal line. It will be placed on the infinite prolongation of the line.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
peetervois
Posts: 6
Joined: Sun Oct 18, 2020 7:29 am

Re: Units, Formula editor and multiplication

Post by peetervois »

Super ! Thanks !
Post Reply