Distance between points/length of a Vector in Formula editor

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
just_a_dick
Posts: 7
Joined: Fri Aug 20, 2021 11:39 pm

Distance between points/length of a Vector in Formula editor

Post by just_a_dick »

I've tried to set a sketch Distance constraint to a distance between two datum points, and could not find an elegant way to do it.

There is distanceToPoint Vector method, and if you write

Code: Select all

<<Pt1>>.Placement.Base.distanceToPoint
in the Formula editor, it will even say that it is a built-in Python method, but calling it like

Code: Select all

<<Pt1>>.Placement.Base.distanceToPoint(<<Pt2>>.Placement.Base)
does not work.

What I currently do is

Code: Select all

sqrt((<<Pt1>>.Placement.Base-<<Pt2>>.Placement.Base)*(<<Pt1>>.Placement.Base-<<Pt2>>.Placement.Base))
Is it possible to express this in a more convenient way?
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Distance between points/length of a Vector in Formula editor

Post by onekk »

just_a_dick wrote: Sat Aug 13, 2022 2:17 pm ...
Please add your FC version info:

http://forum.freecadweb.org/viewtopic.php?f=3&t=2264

It could be important to point out what the problem is as FC is evolving and speaking for a 0.20.0 or a 0.19.4 could be different, and sometimes even on different OS as there could be differences in Python versions of OCC versions that could be relevant to correctly answer to your question.

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/
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Distance between points/length of a Vector in Formula editor

Post by edwilliams16 »

just_a_dick wrote: Sat Aug 13, 2022 2:17 pm
What I currently do is

Code: Select all

sqrt((<<Pt1>>.Placement.Base-<<Pt2>>.Placement.Base)*(<<Pt1>>.Placement.Base-<<Pt2>>.Placement.Base))
Is it possible to express this in a more convenient way?

Code: Select all

(<<Pt1>>.Placement.Base - <<Pt2>>.Placement.Base).Length
just_a_dick
Posts: 7
Joined: Fri Aug 20, 2021 11:39 pm

Re: Distance between points/length of a Vector in Formula editor

Post by just_a_dick »

edwilliams16 wrote: Sat Aug 13, 2022 5:34 pm

Code: Select all

(<<Pt1>>.Placement.Base - <<Pt2>>.Placement.Base).Length
:? Oh, why I didn't try to capitalize the first letter myself…

TYVM!
Post Reply