Trigonometry

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!
Post Reply
BruceArnold
Posts: 2
Joined: Mon Nov 28, 2022 11:43 pm

Trigonometry

Post by BruceArnold »

First of all, I am so grateful to all of the people whose efforts have made FreeCAD a reality. I use the software to create woodworking plans, and since I'm a lousy woodworker, I basically only deal with straight lines. Which makes it pretty easy for me to get by with very rudimentary FreeCAD skills.

I do all of my modelling using scripts, so that I can put in exact dimensions and placements, and keep trying until I get it right. Scripting also lets me use trigonometry when locating the occasional component that is not aligned on all three axes. Herein lies the challenge.

My part is at a 30° angle, but because of where my reference point is located, I'm setting the yaw to 210°, not 30°. Trig tells me that if I want the left vertex to be located at (0,0,0), I should locate the anchor point at (cos30°× partwidth, sin30°× partwidth, 0). When I do that, though, the left vertex is NOT (0,0,0), but a smidge off — more than could be accounted for by rounding (and since I use a script, my placement parameters are many decimal places long).

The plans still come out much better than my workproduct, but I'm wondering if anyone else has come across a situation where math and a FreeCAD vertex don't seem to jibe. If anyone is tempted to reply, let me thank you in advance. Thanks.

Bruce Arnold
Mt Wilson, New South Wales AUSTRALIA

I'm a newbie here, so please be gentle if I'm not au fait with all of the protocols. But ...

.png and . FCStd files attached
Beam.png
Beam.png (17.03 KiB) Viewed 561 times
Beam.FCStd
(10.94 KiB) Downloaded 8 times

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.20.1.29410 (Git)
Build type: Release
Branch: releases/FreeCAD-0-20
Hash: f5d13554ecc7a456fb6e970568ae5c74ba727563
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: English/Australia (en_AU)
User avatar
Jolbas
Posts: 330
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Trigonometry

Post by Jolbas »

How do you get that preselection tooltip?

If I ask for the position of Vertex5 in python console I don't see any significant displacement,

Code: Select all

>>> App.getDocument("Beam").getObject("Shape005").getSubObject("Vertex5").Point
Vector (1.4210854715202004e-14, 0.0, 40.00000000000001)
User avatar
chennes
Veteran
Posts: 3905
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Trigonometry

Post by chennes »

I agree with @Jolbas -- although I do see a couple of nanometers of variation in the selection,

Code: Select all

Gui.Selection.addSelection('Beam','Shape005','Vertex5',-1.90735e-06,-9.53674e-07,40)
when you actually look at the point data itself, I see:

Code: Select all

>>> doc = App.getDocument("Beam")
>>> obj = doc.getObject("Shape005")
>>> shp = obj.Shape
>>> sub = obj.getSubObject("Vertex5")
>>> sub.Point
Vector (1.4210854715202004e-14, 0.0, 40.00000000000001)
Off by 10^-14mm isn't bad for double-precision trig.

ETA: Is it really the rightmost vertex you are concerned about? Its position seems a little suspect (127.0170592217178, -180.0000000000003, 40.00000000000001)mm.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
papyblaise
Veteran
Posts: 7998
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: Trigonometry

Post by papyblaise »

the trigo is perhaps a luxury here, geometry is enough (might as well fish a shrimp with a "French" submarine :lol: )
BruceArnold
Posts: 2
Joined: Mon Nov 28, 2022 11:43 pm

Re: Trigonometry

Post by BruceArnold »

First of all, thank you @Jolbas and @chennes for being so generous as to reply. As for @papyblaise, I'm actually quite chuffed (an Australian word meaning proud of oneself) that I can actually use sine, cosine, and tangent, and sometimes more than one, to find the dimension of a piece.

@Jolbas, the preselection tooltip appears in the lower left corner of my FreeCAD window, and it got there all by itself. In preparing the picture, I did a little cutting and pasting. I'll be studying your code, though, because I'm a believer that EVERYTHING (at least as much as possible) should be done through the python console, and I'd like to absorb how you did what you did.

@Jolbas and @chennes, this particular vertex is off by only a little. But I found that as the angle increases from 30°, the error became greater. The only reason I stumbled on this was that my (blue) vertex was noticeably out of alignment with the green and lavender pieces. And it's much worse at the other end of the beam, after using Pythagoras to check my trig in calculating the length of the piece — sometimes off by up to 2%. Because my woodworking comes only within 5% of plan (when I'm lucky that is), this is really a matter of aesthetics / curiosity rather than necessity.

@chennes, you noted that the rightmost vertex is the one looking suspect. That is the hinge when rotating the piece. My objective was to have the leftmost vertex coincide with the 100mm-width of the green and lavender pieces, so my hinge vertex is located at (100 + cos30° × the 20mm partwidth , 170 + sin30° × 20). In real life, I chamfer the blue piece so that the top aligns with the green-lavender junction. (I haven't quite mastered the art of chamfering pieces through the python console, but I'm trying to learn.)

Once again, thank you so much for taking a look at this and sharing your knowledge. Peace out.
Post Reply