How can we split a spline by another spline(both bezier and line) at point of intersection using maxscript . there is crossinsert but it only works by mouse click…

# Splitting spline at point of intersection

**sharfym**#4

I am trying to do it myself. I have some question regarding interpCurve3D.

when i am trying to find a location on spline using percent and add a vertex on this location using

refineSegment i am getting different location.

here’s the file code:

```
sp = splineShape()
addnewSpline sp
addknot sp 1 #bezierCorner #curve [-46.8842,-25.703,0] [-51.2619,-47.5369,0] [-43.2702,-15.0619,0]
addknot sp 1 #bezierCorner #curve [58.5866,-35.3758,0] [19.0057,28.5584,0] [58.5866,-35.3758,0]
updateshape sp
sp.vertexTicks = on
percent=0.487444
point size:15 pos:(interpCurve3D sp 1 percent) name:"HH" centermarker:on cross:on wirecolor:green
refineSegment sp 1 1 percent
updateshape sp
```

**Senorpablo**#5

When working with splines in Maxscript, there are two different concepts or notions of distance/position/length.

There is vertex based, and arc-length.

Check out these functions in the help to understand the difference:

pathToLengthParam

lengthToPathParam

.5 or 50% doesn’t necessarily mean half the distance(arc-length) with some functions. which are expecting vertex based parameters. I think refinesegment is working in vertex based parameters, when you’re expecting arc-length. You can visualize the difference by creating a dummy and applying a path constraint. If you toggle constant velocity, you can see the difference between vertex and arc-length parameters. Constant velocity uses arc-length.

I looked at the help section for refinesegments and it’s quite misleading. The person who wrote it didn’t understand the difference between vertex and arc-length parameters. They’re talking about distance, when it’s not appropriate or accurate. The examples are misrepresented as if it’s working in arc-length, where it’s actually just coincidence that the results worked out that way.

**sharfy**#6

Thank you @Senorpablo for reply

I am able to refine spline with single segment using ratio with

```
p2 = nearestpathparam sp 1 (interpCurve3D sp 1 percent)
refineSegment sp 1 1 p2
```

how can i add a vertex on a spline with multiple segment if i know ratio where i need to add vertex.

how can i convert full spline percent to segment percent for refineSegment command

i am just lost in

```
nearestpathparam
interpCurve3D
pathInterp
pathtolengthparam
interpCurve3D
lengthInterp
```

still trying to figure out…

**aaandres**#7

If you mean ‘ratio’ as lengthParam (uniform length), then:

- Convert it to ‘pathRatio’ with
**lengthToPathParam**command. - After that, follow refineSegment instructions:

Given a path interpolation parameter u in a spline of m segments, the target segment is:

n = (m * u) as integer + 1

The segment parameter is:

f = (u-(n-1)/m) * m

This can be refactored to the following which will reduce roundoff error in the calculation:

f = u * m - n + 1

**sharfym**#9

HI

I have some lines with overlapping vertices, i want to find set of all lines than can create close shape and create a close shape.

any ideas ?

**sharfym**#11

thank you for reply

but my lines are not all three or four sided close shapes, they also include bezier curves.

thanks

**aaandres**#12

What you show here in this image is something similar to one I solved in the past. I used Graph Theory, and searched for all Hamiltonian circuits. Wasn’t easy at all as I remember. You can simplify your graph by just identifying each line by its start and end vertex, but not if you can have some cases as the “green line” where another line hits a centered vertex. By the way, you should know it’s an NP algorithm.

In case you get to it (get to have all circuits), you have a second problem: you have to decide which ones of them are the ones you want (in your case, you have big circuits that can be reduced to two or three smaller ones). If you can simplfy your graph, the “good ones” will be surely the smaller ones (less number of nodes) but if you can’t (because you have some cases as the green line), I can’ t imagine how to select them. Perhaps calculating their area. Really an interesting problem!

Good luck!