[Closed] Find intersection point between a vector (2 points) and closed spline
Hi
Is there any script or trick to find intersection point between a vector (2 points) and closed spline ?
I know that there is good page here in this forums in which you can find the 2 lines intersection point, but how about a line and closed spline.
If a line has an intersection with a closed spline ( segment ) is there a way to find the intersection point?
Thanks in advance
2 points sounds more like segment not vector.
Collect points of your spline using interpCurve3D and then check segmentSegment intersection between your segment and segment defined by spline point n and point n+1
Thanks Serejah for the reply.
The scene is sth like this
Thetex = text text:"D" size:115
centerpivot thetex
thetex.pos = [0,0,0]
pt1 = point size:.5 cross:on box:off axistripod:off wirecolor:(color 88 144 225)
pthCon = pt1.pos.controller = Path_Constraint Follow:on path:$Text001
deleteKeys pt1.pos.controller #allKeys
pt1.pos.controller.percent = 45.4
pt2 = point pos:[7.3,37.1,0] size:.5 cross:off box:on axistripod:off wirecolor:(color 88 144 225)
NeedPoiont = point pos:[-26.65,36.5,0] size:.5 cross:on box:off axistripod:off wirecolor:Red
pthCon = needPoiont.pos.controller = Path_Constraint Follow:on path:$Text001
deleteKeys needPoiont.pos.controller #allKeys
needPoiont.pos.controller.percent = 46.0
I need the red point. and the points are not constrainted just to create the scene i used path constraint .
I try to say , by The
vector1 = ( pt2.center - the text.center)
is it possible to find the red point in this scene.
As you see the spline doesn’t have enough vertices, I have the 2 blue points and need the red point on the segment of spline
could you example what you said , i didn’t get what you’ve said
something like this
delete objects
Thetex = text text:"D" size:115
centerpivot thetex
thetex.pos = [0,0,0]
pt1 = point size:.5 cross:on box:off axistripod:off wirecolor:(color 88 144 225)
pthCon = pt1.pos.controller = Path_Constraint Follow:on path:$Text001
deleteKeys pt1.pos.controller #allKeys
pt1.pos.controller.percent = 45.4
pt2 = point pos:[7.3,37.1,0] size:.5 cross:off box:on axistripod:off wirecolor:(color 88 144 225)
NeedPoiont = point pos:[-26.65,36.5,0] size:.5 cross:on box:off axistripod:off wirecolor:Red
pthCon = needPoiont.pos.controller = Path_Constraint Follow:on path:$Text001
deleteKeys needPoiont.pos.controller #allKeys
needPoiont.pos.controller.percent = 46.0
convertToSplineShape Thetex
theTexPts = #()
for i=1 to numsplines Thetex do (
pts = for p=0.0 to 1.0 by 0.01 collect interpCurve3D Thetex i p
append theTexPts pts
)
for splinePts in theTexPts do (
for p in splinePts do point pos:p centermarker:on cross:off wirecolor:yellow
)
fn segSegIntersection a1 a2 b1 b2 = (
-- calc whether segment a1a2 intersects segment b1b2
)
a1 = Thetex.center
a2 = pt2.center
pointsOfIntesection = #()
for s=1 to theTexPts.count do (
splinePts = theTexPts[s]
count = splinePts.count
for i=1 to count do (
j = if i == count then 1 else i + 1
result = segSegIntersection a1 a2 splinePts[i] splinePts[j]
if result != undefined do (
append pointsOfIntesection #( s /* spline index */, result /* point of intersection */ )
)
)
)
i use this function to find the intersection between to splines or vectors from the sticky page Geometrical calculations : points, lines, planes : intersections,
fn lineLineIntersect pA pB pC pD =
(
local a=pB-pA
local b=pD-pC
local c=pC-pA
local cross1 = cross a b
local cross2 = cross c b
pA + ( a*( (dot cross2 cross1)/((length cross1)^2) ) )
)
if i use this fn instead of fn segSegIntersection a1 a2 b1 b2 still doesnt get the intersection
How are you suppose to have a valid intersection point using lineLine Intersection? lineLine Intersection will return the intersection point that is outside of spline shape most of the time.
google for segmentSegment intersection. There’re plenty of examples on stackoverflow and github available
or…
(
delete objects
txt = text text:"G"
txt.center = [0,0,0]
p1 = [-50,-50,0]
p2 = [ 25, 50,0]
point pos:p1 centermarker:on cross:off wirecolor:yellow
point pos:p2 centermarker:on cross:off wirecolor:yellow
redrawViews()
gc()
t1=timestamp()
hf = heapfree
with redraw off (
with undo off (
addModifier txt (Extrude amount:666)
vec = normalize (p1 - p2)
_ray = ray vec (p1 + [0,0,txt.center.z])
rmgi = RayMeshGridIntersect()
rmgi.initialize 20
rmgi.addNode txt
rmgi.buildGrid()
-- rmgi.intersectray _ray.pos _ray.dir true
hits = rmgi.intersectSegment p1 p2 true
if hits > 0 do (
for i=1 to hits do (
point pos:(p1 - (rmgi.getHitDist i) * vec) centermarker:on cross:off wirecolor:orange
)
)
rmgi.free()
deleteModifier txt 1
)
)
format "Time: %sec. Mem: %
" ((timestamp()-t1)/1000 as float) (hf-heapfree)
)