Dimensioning to point of intersection

Discussions about the development of the TechDraw workbench
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
PeterPNoster
Posts: 72
Joined: Mon Sep 02, 2019 8:24 pm
Location: Switzerland

Re: Dimensioning to point of intersection

Post by PeterPNoster »

Copied the macro in an new file.
Made a new usermacro with.
Changed to TechDraw.
Selected the two lines.
Executed the macro.
No changes on the TechDraw, errors in the Output window.

Traceback (most recent call last):
File "/home/fabrizio/.FreeCAD/Macro/EdgeIntersection.FCMacro", line 92, in <module>
find_intersection()
File "/home/fabrizio/.FreeCAD/Macro/EdgeIntersection.FCMacro", line 61, in find_intersection
cur_view.getEdgeByIndex(a).Vertexes, indices)))
File "/home/fabrizio/.FreeCAD/Macro/EdgeIntersection.FCMacro", line 61, in <lambda>
cur_view.getEdgeByIndex(a).Vertexes, indices)))
<class 'AttributeError'>: 'TechDraw.DrawProjGroupItem' object has no attribute 'getEdgeByIndex'
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Dimensioning to point of intersection

Post by wandererfan »

PeterPNoster wrote: Mon Sep 09, 2019 7:23 pm No changes on the TechDraw, errors in the Output window.
getEdgeByIndex is pretty new (last weekend). It might not be in freecad-daily yet.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimensioning to point of intersection

Post by reox »

wandererfan wrote: Mon Sep 09, 2019 7:22 pm I like yours, , but you need to unscale the answer before returning it.
Thanks :) But you directly wrote down the equations for the point instead of using the linear equation system which is probably the better way.
Also thanks for the hint with the scale, I added this to my macro now as well!
wandererfan wrote: Mon Sep 09, 2019 7:33 pm getEdgeByIndex is pretty new (last weekend). It might not be in freecad-daily yet.
I'm already on:

Code: Select all

OS: Debian GNU/Linux bullseye/sid (i3/i3)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18149 (Git)
Build type: Release
Branch: master
Hash: fb5d7fa076d9cfa00c5ef343e061275c7b558ab5
Python version: 3.7.4+
Qt version: 5.11.3
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Austria (de_AT)
I also tested now with a ProjGroup and it works as well for me.
PeterPNoster
Posts: 72
Joined: Mon Sep 02, 2019 8:24 pm
Location: Switzerland

Re: Dimensioning to point of intersection

Post by PeterPNoster »

@wandererfan: Ok, I will retry in a few days.

Thank you folks!
PeterPNoster
Posts: 72
Joined: Mon Sep 02, 2019 8:24 pm
Location: Switzerland

Re: Dimensioning to point of intersection

Post by PeterPNoster »

I get the following result with your new 93 lines macro.
No errors in the output window.
Intersection_point_macro_93_lines.png
Intersection_point_macro_93_lines.png (44.1 KiB) Viewed 1767 times
OS: Linux Mint 19.2 (X-Cinnamon/cinnamon)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18142 (Git) AppImage
Build type: Release
Branch: master
Hash: 256f85678fef73807f479de19b4e3dcfd6fd1c89
Python version: 3.7.3
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Switzerland (de_CH)
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Dimensioning to point of intersection

Post by vocx »

reox wrote: Mon Sep 09, 2019 7:36 pm ...But you directly wrote down the equations for the point instead of using the linear equation system which is probably the better way.
Maybe wandererfan didn't want to use a big dependency; I mean, your code works but it requires Numpy. Imagine not having it. Using a different approach is maybe preferred if you can do it with the tools provided only by FreeCAD. I am not sure, but I think the Draft workbench has among many of its tools (internal code) functions to calculate the intersection of two lines.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimensioning to point of intersection

Post by reox »

vocx wrote: Tue Sep 10, 2019 6:16 am but it requires Numpy.
Isn't numpy not a dependency of freecad itself? At least if you git grep it, there are some hits in the code.
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Dimensioning to point of intersection

Post by wandererfan »

vocx wrote: Tue Sep 10, 2019 6:16 am Maybe wandererfan didn't want to use a big dependency;
Most likely he couldn't remember how to solve simultaneous equations early on a Sunday morning before the coffee kicked in!
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: Dimensioning to point of intersection

Post by vocx »

reox wrote: Tue Sep 10, 2019 8:33 am Isn't numpy not a dependency of freecad itself? At least if you git grep it, there are some hits in the code.
I honestly don't know. I don't think Numpy is advertised as a core dependency of FreeCAD, the way Boost or Coin are.

As far as I know, Numpy is used in the Plot Workbench, both Numpy and Matplotlib, of course. But the Plot workbench is not a core component of the system; it was recently moved to a separate repository together with Ship. Maybe the intention was to make them optional and no longer part of the standard workbenches. Ship WB problems and it's future in core (0.18), https://github.com/FreeCAD/freecad.plot, https://github.com/FreeCAD/freecad.ship

I personally think that a lot of the geometrical algorithms used in Draft and Arch, and elsewhere, could benefit from using Numpy or SciPy functions. But the code is completely devoid of it. It's like they purposefully decided to avoid Numpy. Instead, a lot of vector functions are coded from scratch, for example, DraftVecUtils.py which provides a bunch of support functions for Draft tools.

Looking at the freecad-daily-python3 package in Ubuntu, python3-matplotlib is in fact a dependency, which of course installs python3-numpy. I also think that Matplotlib is used in FEM to create some graphs.

But really, everywhere else, I don't know what other workbenches use Numpy prominently. The Third Party Libraries page doesn't mention it as one of its dependencies, nor does the Conda page.

Again, I'm not against using Numpy, however, it seems that currently it isn't considered a top dependency in FreeCAD. On the contrary, I would prefer to bring more of Numpy and SciPy to FreeCAD, to improve its status as a scientific-engineering piece of software.

I think Numpy is all about is vectors and vectorized operations, but the core FreeCAD system already uses the Eigen3 C++ libraries, which is probably why Numpy wasn't considered from the beginning.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
reox
Posts: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimensioning to point of intersection

Post by reox »

vocx wrote: Tue Sep 10, 2019 5:16 pm I personally think that a lot of the geometrical algorithms used in Draft and Arch, and elsewhere, could benefit from using Numpy or SciPy functions. But the code is completely devoid of it. It's like they purposefully decided to avoid Numpy. Instead, a lot of vector functions are coded from scratch, for example, DraftVecUtils.py which provides a bunch of support functions for Draft tools.
I mean, who hasn't coded his own vector library? :mrgreen: (I actually did and it was quite fun - but the stuff isnt very optimized...)
I think as the majority of the code is written in C, numpy would have no real use there.
I found out that there are already function for example to calculate angles between vectors, which is easier than normalizing the vector and taking the dot product but I did not really find functions to intersect lines and so on... but I did not really search very hard for it.
I now searched for "Freecad vector library" and got this wiki page: FreeCAD_vector_math_library - essentially it makes function out of methods from the FreeCAD.Vector class? Not sure how this can be useful? Or is this some vintage, when the Vector class wasn't fully exposed to the python world? (It looks like it, there is also a forum entry from 2017 mentioning this page)
Anyways, if there would be a wiki page describing stuff like defining lines, planes, ... and intersecting them etc, I would probably use it instead of numpy ;)
Post Reply