Hello,
Could anyone tell me how I make dimensioning to an intersection point?
Needed when dealing with sheet metal dimensioning.
Thanks!
Don't have a tool for this yet, but it would make a good Feature Request.PeterPNoster wrote: ↑Mon Sep 02, 2019 8:39 pmCould anyone tell me how I make dimensioning to an intersection point?
Needed when dealing with sheet metal dimensioning.
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)
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 amThe 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")