Dimensioning to point of intersection
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
-
- Posts: 72
- Joined: Mon Sep 02, 2019 8:24 pm
- Location: Switzerland
Dimensioning to point of intersection
Hello,
Could anyone tell me how I make dimensioning to an intersection point?
Needed when dealing with sheet metal dimensioning.
Thanks!
Could anyone tell me how I make dimensioning to an intersection point?
Needed when dealing with sheet metal dimensioning.
Thanks!
- wandererfan
- Veteran
- Posts: 6326
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Dimensioning to point of intersection
Don't have a tool for this yet, but it would make a good Feature Request.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.
In v0.19 you can "fake it" by adding a cosmetic vertex and dimensioning to that.
Re: Dimensioning to point of intersection
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!
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!
Re: Dimensioning to point of intersection
Perhaps related: issue #3004.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
-
- Posts: 72
- Joined: Mon Sep 02, 2019 8:24 pm
- Location: Switzerland
Re: Dimensioning to point of intersection
Hi everybody,
Something like this would be helpful enough:
Something like this would be helpful enough:
-
- Posts: 72
- Joined: Mon Sep 02, 2019 8:24 pm
- Location: Switzerland
Re: Dimensioning to point of intersection
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!
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!
Re: Dimensioning to point of intersection
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:
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...)
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)
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...)
- Attachments
-
- Foobar.FCStd
- (14.62 KiB) Downloaded 162 times
-
- Posts: 72
- Joined: Mon Sep 02, 2019 8:24 pm
- Location: Switzerland
Re: Dimensioning to point of intersection
Thank you reox for the solution,
I've made an test with the following TechDraw. 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.
I've made an test with the following TechDraw. 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.
Re: Dimensioning to point of intersection
Hmm interessting, I thought that I had the coordinate swap right Okay, then the minus sign in the macro is un-neccessary. Actually, I posted a wrong version of the macro
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
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
- Veteran
- Posts: 6326
- Joined: Tue Nov 06, 2012 5:42 pm
- Contact:
Re: Dimensioning to point of intersection
I had some "spare time" on the weekend too. I like yours, , but you need to unscale the answer before returning it.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.
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")