## Units, Formula editor and multiplication

About the development of the Part Design module/workbench. PLEASE DO NOT POST HELP REQUESTS HERE!
peetervois
Posts: 6
Joined: Sun Oct 18, 2020 7:29 am

### Units, Formula editor and multiplication

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
Posts: 30620
Joined: Tue Mar 17, 2015 9:14 am

### Re: Units, Formula editor and multiplication

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.
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
peetervois
Posts: 6
Joined: Sun Oct 18, 2020 7:29 am

### Re: Units, Formula editor and multiplication

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
Screenshot_2020-10-26_15-35-44.png (51.48 KiB) Viewed 369 times
chrisb
Posts: 30620
Joined: Tue Mar 17, 2015 9:14 am

### Re: Units, Formula editor and multiplication

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.
You need at least FreeCAD 0.19.23300 to edit my current sketches.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
peetervois
Posts: 6
Joined: Sun Oct 18, 2020 7:29 am

Super ! Thanks !

### Who is online

Users browsing this forum: No registered users and 2 guests