[Solved by PR 1053] Error with angles in formulas

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
plgarcia
Posts: 305
Joined: Wed Jun 17, 2015 9:47 pm
Location: Near Paris (France)

[Solved by PR 1053] Error with angles in formulas

Postby plgarcia » Thu Sep 28, 2017 11:57 am

There are problems using angles in formulas.
The value of the angle used in the formula is in radians but considered as degrees.

My example 2 cube.
I set the angle of the firs cube to 45° and shown in picture1.
Then I set the angle of the second cube with a formua as being equals to the angle of the first cube as shown in pcture2.
The value takent by this angle is 0.79 as shown in picture3.
0.79 is the value in radians of à 45°angle, but it is considered as being in degrees what is wrong, what shows the position of the 2 cubes on the view.

Here are the logs seen in Python console.
>>> FreeCAD.getDocument("Sans_nom").getObject("Box").Placement = App.Placement(App.Vector(0,0,0),App.Rotation(App.Vector(0,0,1),45))
>>> FreeCAD.getDocument("Sans_nom").getObject("Box001").Placement = App.Placement(App.Vector(12.8799,10.1293,6.24988),App.Rotation(App.Vector(0,0,1),0.79))
>>> App.getDocument('Sans_nom').Box001.setExpression('Placement.Rotation.Angle', u'Cube.Placement.Rotation.Angle')
>>> FreeCAD.getDocument("Sans_nom").getObject("Box001").Placement = App.Placement(App.Vector(12.8799,10.1293,6.24988),App.Rotation(App.Vector(0,0,1),0.79))
>>>
Also shown in picture4.

I understand that is or may become a problem, as the value that should be used in trigonometric finctions should be radians and the representation is in degrees. Here there is a confusion of the internal representation and the presentation in the GUI.

For me it is a bug.

Regards
Attachments
picture4.png
picture4.png (24.79 KiB) Viewed 1241 times
picture3.png
picture3.png (20.54 KiB) Viewed 1241 times
picture2.png
picture2.png (21.92 KiB) Viewed 1241 times
picture1.png
picture1.png (19.41 KiB) Viewed 1241 times
Last edited by plgarcia on Thu Dec 07, 2017 12:24 pm, edited 1 time in total.
plgarcia
Posts: 305
Joined: Wed Jun 17, 2015 9:47 pm
Location: Near Paris (France)

Re: Errors in formulas (Angles, references, ...)

Postby plgarcia » Fri Sep 29, 2017 9:57 am

I found a other bug.
If in a formula an object is referenced with its Label, and the label of the object is changed, then these formulas become invalid.

If an object Label is changed formulas using this label should be changed.
An other way could be to only store internal references and replace them when the formula is displayed or edited.
User avatar
Kunda1
Posts: 7353
Joined: Thu Jan 05, 2017 9:03 pm

Re: Error with angles in formulas

Postby Kunda1 » Fri Sep 29, 2017 10:11 am

eivindkvedalen wrote:ping
Care to weigh in @eivindkvedalen ?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
NormandC
Posts: 18534
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Error with angles in formulas

Postby NormandC » Sat Sep 30, 2017 8:17 pm

plgarcia,

In the "Help on using FreeCAD" forum, there is a "Bug submission guidelines" topic at the top of the page.

It states
2. If you are unsure, discuss the problem on the forum first. Open a new topic here on the forum, in the help section
This is a development forum that is dedicated to discussion about actual development and coding, not bug reporting. Unfortunately, the moderators do not care about having topics posted all over the place. :|

One other thing in point no. 4:
4. Always include your FreeCAD version information.
A bug report without mention of the FreeCAD info severely reduces its worthiness. And always test with FC compiled from current master or from the very latest development build available.
plgarcia
Posts: 305
Joined: Wed Jun 17, 2015 9:47 pm
Location: Near Paris (France)

Re: Error with angles in formulas

Postby plgarcia » Mon Oct 02, 2017 11:46 am

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.17.12284 (Git)
Build type: Release
Branch: master
Hash: 2244292552c004e6b506af9e1e98d3423e524ee7
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.1.0
Locale: French/France (fr_FR)
plgarcia
Posts: 305
Joined: Wed Jun 17, 2015 9:47 pm
Location: Near Paris (France)

Re: Error with angles in formulas

Postby plgarcia » Mon Oct 02, 2017 12:33 pm

It is a bug, there is no doubt to my mind, and I have not found any bug of that kind already reported.

When reporting a bug, I have been asked to open a discussion in the forum, that is what I did. But next time I will open it in "open discussion" forum.


Here is the bug report.
https://www.freecadweb.org/tracker/view.php?id=3200

I test on the latest build available here :
https://github.com/FreeCAD/FreeCAD/releases
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Error with angles in formulas

Postby eivindkvedalen » Tue Oct 03, 2017 7:48 am

plgarcia wrote:
Mon Oct 02, 2017 12:33 pm
It is a bug, there is no doubt to my mind, and I have not found any bug of that kind already reported.

When reporting a bug, I have been asked to open a discussion in the forum, that is what I did. But next time I will open it in "open discussion" forum.


Here is the bug report.
https://www.freecadweb.org/tracker/view.php?id=3200

I test on the latest build available here :
https://github.com/FreeCAD/FreeCAD/releases
Please test https://github.com/eivindkv/FreeCAD/tree/Fix_issue_3200 , to see if it resolve your problem. If it does, I'll make a pull request.

Eivind
plgarcia
Posts: 305
Joined: Wed Jun 17, 2015 9:47 pm
Location: Near Paris (France)

Re: Error with angles in formulas

Postby plgarcia » Wed Oct 04, 2017 9:16 am

Sorry, that was the first time I compiled FreeCad and it took some time to set the environment right and have it working.
Your change works!
45° is 45° and sin(45°) is 0,71!

I tested it on Linux Ubuntu 17.04

Thank you
Regards
Pascal Garcia
plgarcia
Posts: 305
Joined: Wed Jun 17, 2015 9:47 pm
Location: Near Paris (France)

Re: Error with angles in formulas

Postby plgarcia » Wed Oct 04, 2017 11:43 am

What about this new bug I found arround formulas.

2 cubes, Cube and Cube001.

I set cube001 Angle as bin equal to Cube.Placement.Rotation.Angle.
OK it works at this stage, and the correction you made is fine.

Now I rename Cube in Cube2. (change the label).

Then the gui does not display any longer the properties of the objects.

And i get these messages in linux console :
FreeCAD 0.17, Libs: 0.17RUnknown
© Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2017
##### #### ### ####
# # # # # #
# ## #### #### # # # # #
#### # # # # # # # ##### # #
# # #### #### # # # # #
# # # # # # # # # ## ## ##
# # #### #### ### # # #### ## ## ##

QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: Aucun fichier ou dossier de ce type
Unhandled Base::Exception caught in GUIApplication::notify.
The error message is: Property not found: Cube
Unhandled Base::Exception caught in GUIApplication::notify.
The error message is: Property not found: Cube
Unhandled Base::Exception caught in GUIApplication::notify.
The error message is: Property not found: Cube
Unhandled ...


Eventually somtimes but not always FreeCad crashes!

Saving the object works but after loading the faulty file, the problem appears again as soon as the properties of Cube001 are selected.

In fact there is no simple way to solve the problem, but decompressing de saved file, correct by hand the error (if able to identify it) and recompress it.

There are 3 problems.
1 - Changing the label should change all formulas that refer to this label. This problem may occur while deleting an object, pasting an object as the referenced object does no longer exist etc.
2 - When for whatever reason we end in such a situation where an error occurs, the exception should be trapped, the formula should be invalidated (in order no to be evaluated and to avoid multiple cascade errors), and an error should be reported on the gui (black objet for example, or a red tick on the property, ...) with a clear reason displayed to allow the user to identify the problem and solve it.
3 - The gui should not be frozen.

Do you want me to report a bug on this topic?


Regards
eivindkvedalen
Posts: 602
Joined: Tue Jan 29, 2013 10:35 pm

Re: Error with angles in formulas

Postby eivindkvedalen » Sun Oct 08, 2017 5:02 pm

plgarcia wrote:
Wed Oct 04, 2017 11:43 am

There are 3 problems.
1 - Changing the label should change all formulas that refer to this label. This problem may occur while deleting an object, pasting an object as the referenced object does no longer exist etc.
2 - When for whatever reason we end in such a situation where an error occurs, the exception should be trapped, the formula should be invalidated (in order no to be evaluated and to avoid multiple cascade errors), and an error should be reported on the gui (black objet for example, or a red tick on the property, ...) with a clear reason displayed to allow the user to identify the problem and solve it.
3 - The gui should not be frozen.

Do you want me to report a bug on this topic?


Regards
This is already reported, see https://freecadweb.org/tracker/view.php?id=3151 and https://freecadweb.org/tracker/view.php?id=2766 , but I haven't had time to fix them.

Eivind