Dimensioning to point of intersection

Discussions about the development of the TechDraw workbench
PeterPNoster
Posts: 9
Joined: Mon Sep 02, 2019 8:24 pm

Dimensioning to point of intersection

Postby PeterPNoster » Mon Sep 02, 2019 8:39 pm

Hello,
Could anyone tell me how I make dimensioning to an intersection point?
Needed when dealing with sheet metal dimensioning.

Thanks!
Feature_intersection.PNG
Feature_intersection.PNG (18.03 KiB) Viewed 664 times
wandererfan
Posts: 3091
Joined: Tue Nov 06, 2012 5:42 pm

Re: Dimensioning to point of intersection

Postby wandererfan » Tue Sep 03, 2019 1:03 am

PeterPNoster wrote:
Mon Sep 02, 2019 8:39 pm
Could anyone tell me how I make dimensioning to an intersection point?
Needed when dealing with sheet metal dimensioning.
Don't have a tool for this yet, but it would make a good Feature Request.

In v0.19 you can "fake it" by adding a cosmetic vertex and dimensioning to that.
aapo
Posts: 88
Joined: Mon Oct 29, 2018 6:41 pm

Re: Dimensioning to point of intersection

Postby aapo » Tue Sep 03, 2019 5:11 am

Forum threads relevant to this request:

https://forum.freecadweb.org/viewtopic.php?f=35&t=36208
https://forum.freecadweb.org/viewtopic.php?f=35&t=36614

On the 2nd thread there's an example about manually positioning the "cosmetic vertices" with v0.19_pre, as WandererFan mentioned. This kind of workaround can be used, but unfortunately it's very clumsy to use at the moment, as you need to enter the 2D coordinates manually in the drawing coordinate system. Please try the v0.19_pre, or wait a few months! :D
chrisb
Posts: 19044
Joined: Tue Mar 17, 2015 9:14 am

Re: Dimensioning to point of intersection

Postby chrisb » Tue Sep 03, 2019 6:23 am

Perhaps related: issue #3004.
PeterPNoster
Posts: 9
Joined: Mon Sep 02, 2019 8:24 pm

Re: Dimensioning to point of intersection

Postby PeterPNoster » Tue Sep 03, 2019 7:38 am

Hi everybody,
Something like this would be helpful enough:
Intersection_Point_2.PNG
Intersection_Point_2.PNG (87.73 KiB) Viewed 609 times
PeterPNoster
Posts: 9
Joined: Mon Sep 02, 2019 8:24 pm

Re: Dimensioning to point of intersection

Postby PeterPNoster » Wed Sep 04, 2019 2:46 pm

Hi there,
I've added my first feature request into the tracker.
https://freecadweb.org/tracker/view.php?id=4114

Let's wait and see what happens.

Thank you, for making FreeCAD such a fantastic piece of software!
reox
Posts: 664
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimensioning to point of intersection

Postby reox » Thu Sep 05, 2019 7:36 pm

Can you get the coordinates of the two edges from the DrawViewPart via python, no? I played around with it and got to this solution:

Code: Select all

import numpy as np                            
(p, q), (r, s) = map(lambda x: x.getLinearPoints(), FreeCADGui.Selection.getSelection())
# Want to solve: p + t(q - p) = r + v(s - r)
# t and v are constants, p,q,r,s are vectors
a = np.array([[q.x - p.x, -s.x + r.x], [q.y - p.y, -s.y + r.y]])
b = np.array([r.x - p.x, r.y - p.y])
t, v = np.linalg.solve(a, b)
res = FreeCAD.Vector(p.x + t * (q.x - p.x), r.y + v * (s.y - r.y), 0)
print(res)
With two length dimensions (you create the length dimensions on the two lines where you want to calculate the intersection point) as helpers and the macro, you can calculate the point of intersection of two lines.
It would be super nice to create the cosmetic vertex using the macro too ;)

Attached is an example where I created the point by using this script (I deliberately created the sketch in such a way that I know what the coordinate would be...)
2019-09-05-213436_771x699_scrot.png
2019-09-05-213436_771x699_scrot.png (43.14 KiB) Viewed 421 times
Attachments
Foobar.FCStd
(14.62 KiB) Downloaded 12 times
PeterPNoster
Posts: 9
Joined: Mon Sep 02, 2019 8:24 pm

Re: Dimensioning to point of intersection

Postby PeterPNoster » Sat Sep 07, 2019 12:37 pm

Thank you reox for the solution,
I've made an test with the following TechDraw.
Intersection_point_macro.png
Intersection_point_macro.png (36.96 KiB) Viewed 353 times
The output was:
Vector (28.69615242270663, -6.5801270189221945, 0.0)

The cosmetic vertex tool gave me the point at the bottom.
Then I've changed the negative value into a positive one. And voila.

The vertical distance between the point and the relevant line is 0.00.
reox
Posts: 664
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimensioning to point of intersection

Postby reox » Mon Sep 09, 2019 7:51 am

Hmm interessting, I thought that I had the coordinate swap right :D Okay, then the minus sign in the macro is un-neccessary. Actually, I posted a wrong version of the macro :oops:

But, I managed to make the macro even better! You can actually get the Coordinates of an Edge directly using python.
So you can simply select two edges in the View and the macro will to the rest.
The full Macro can be found here: https://github.com/reox/FreeCAD_macros/ ... on.FCMacro
It is also possible to create the cosmetic vertex directly from the macro.

Please test and give feedback :)
wandererfan
Posts: 3091
Joined: Tue Nov 06, 2012 5:42 pm

Re: Dimensioning to point of intersection

Postby wandererfan » Mon Sep 09, 2019 7:22 pm

reox wrote:
Mon Sep 09, 2019 7:51 am
The full Macro can be found here: https://github.com/reox/FreeCAD_macros/ ... on.FCMacro
It is also possible to create the cosmetic vertex directly from the macro.
I had some "spare time" on the weekend too. I like yours, , but you need to unscale the answer before returning it.

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# create Cosmetic Vertex at apparent intersection of 2 straight edges.
import FreeCAD
import Part
import math
import TechDraw
import re

#edge names are assumed to be EdgeNNN where NNN is actual index 
#edges are assumed to be on plane ((0, 0, 0), (0, 0, 1), (1, 0, 0))

def invertY(pt):
    result = App.Vector(pt.x, -pt.y, pt.z)
    return result;

def slopeInterceptFromPoints(p0, p1):
    m = (p0.y - p1.y) / (p0.x - p1.x)
    b = p0.y - (m * p0.x)
    return m, b

def apparentIntersection(e0, e1):
    e0First = invertY(e0.firstVertex().Point)
    e0Last  = invertY(e0.lastVertex().Point)
    e1First = invertY(e1.firstVertex().Point)
    e1Last = invertY(e1.lastVertex().Point)

    m0, b0 = slopeInterceptFromPoints(e0First, e0Last)
    m1, b1 = slopeInterceptFromPoints(e1First, e1Last)

    x = (b1 - b0) / (m0 - m1)
    y = (m0 * x) + b0
    return App.Vector(x, y, 0.0)

s = FreeCADGui.Selection.getSelectionEx()
if not s:
    print("please select a View and 2 edges!")
#TODO: check that selected subobjects are in fact edges!

dvp = s[0].Object                   #get the View
n0 = s[0].SubElementNames[0]        #get the names of 2 edges
n1 = s[0].SubElementNames[1]

i0 = int(re.findall(r'\d+$', n0)[-1])
i1 = int(re.findall(r'\d+$', n1)[-1])

e0 = dvp.getEdgeByIndex(i0)
e1 = dvp.getEdgeByIndex(i1)

intersect = apparentIntersection(e0, e1)

scale = dvp.Scale
dvp.makeCosmeticVertex(intersect / scale)

print("finished")
cron