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

Dimensioning to point of intersection

Post by PeterPNoster »

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 4722 times
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 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: 626
Joined: Mon Oct 29, 2018 6:41 pm

Re: Dimensioning to point of intersection

Post by aapo »

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
Veteran
Posts: 54293
Joined: Tue Mar 17, 2015 9:14 am

Re: Dimensioning to point of intersection

Post by chrisb »

Perhaps related: issue #3004.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
PeterPNoster
Posts: 72
Joined: Mon Sep 02, 2019 8:24 pm
Location: Switzerland

Re: Dimensioning to point of intersection

Post by PeterPNoster »

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

Re: Dimensioning to point of intersection

Post by PeterPNoster »

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: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimensioning to point of intersection

Post by reox »

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 4479 times
Attachments
Foobar.FCStd
(14.62 KiB) Downloaded 162 times
PeterPNoster
Posts: 72
Joined: Mon Sep 02, 2019 8:24 pm
Location: Switzerland

Re: Dimensioning to point of intersection

Post by PeterPNoster »

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 4411 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: 929
Joined: Sat Aug 13, 2016 10:06 am
Contact:

Re: Dimensioning to point of intersection

Post by reox »

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 :)
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Dimensioning to point of intersection

Post by wandererfan »

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")
Post Reply