https://www.keanw.com/2013/07/finding-an-autocad-spline-between-two-others-using-net.htmlhttps://www.theswamp.org/index.php?topic=58736.0How to determine the NurbCurve3d center between two NurbCurve3ds?
Kean Walmsley:
I chose to interpret this in the following way: given two NurbCurve3d objects, create a NurbCurve3d that sits exactly between the two. NurbCurve3d are “AcGe” classes – which means they’re non-graphical – so I’ve broadened the scope to deal with Splines as they have a close relationship with the NurbCurve3d class (in fact there are handy methods to convert between the two classes). Here’s some more information on NURBS, for those with an interest.
I’ve also chosen to deal with one fairly specific case: one where the Splines (and the equivalent NurbCurve3ds) have exactly the same degree and period as well as the same number of control points, knots and weights. Which makes things much easier: while it should be possible – with enough effort and code – to find a way to parameterize the two curves and create points on a curve between the two – fitting a curve along those points – I’ve chosen not to address that more general problem. At least not in this post.
So what I’ve done is actually very simple: between two similarly-sized NurbCurve3d objects, we step through the three primary collections of each – control points, knots and weights – and create three new collections for the new curve that contain the “average” values of the data from the two source objects. I’m far from being a NURBS expert, but I believe this approach to be reasonable for this particular category of Spline (at least it seems to work well enough).
Bear in mind that this also won’t work with Splines that are defined by fit – rather than control – points. At least I don’t expect it to.
![smiley :-)](http://www.theswamp.org/Smileys/black/smiley.gif)
(defun _check
-curve
(spl1 spl2
) (and (= (xdrx
-getpropertyvalue g1
"degree") (xdrx-getpropertyvalue g2 "degree")
)
(= (xdrx-getpropertyvalue g1 "isPeriodic")
(xdrx-getpropertyvalue g2 "isPeriodic")
)
(= (xdrx-getpropertyvalue g1 "numcontrolpoints")
(xdrx-getpropertyvalue g2 "numcontrolpoints")
)
(= (xdrx-getpropertyvalue g1 "numKnots")
(xdrx-getpropertyvalue g2 "numKnots")
)
(= (xdrx-getpropertyvalue g1 "numWeights")
(xdrx-getpropertyvalue g2 "numWeights")
)
)
)
"\nSelect the first SPLINE <exit>:"
'((0 . "spline"))
)
)
)
"\nSelect the second SPLINE <exit>:"
'((0 . "spline"))
)
)
)
(setq g1
(xdge::constructor e1
)) (setq g2
(xdge::constructor e2
)) (_check-curve e1 e2)
)
(xdrx-begin)
(setq degree
(xdrx
-getpropertyvalue g1
"degree") period (xdrx-getpropertyvalue g1 "isPeriodic")
pts1 (xdrx-getpropertyvalue g1 "controlpoints")
pts2 (xdrx-getpropertyvalue g2 "controlpoints")
knots1 (xdrx-getpropertyvalue g1 "knots")
knots2 (xdrx-getpropertyvalue g2 "knots")
numKnots (xdrx-getpropertyvalue g1 "numKnots")
numWeights (xdrx-getpropertyvalue g1 "numWeights")
)
(xdrx-line-midp x y)
)
pts1
pts2
)
)
(/ (+ x y) 2.0)
)
knots1
knots2
)
)
knots
(list (/ (+ (xdrx
-getpropertyvalue g1
"weightat" i
) (xdrx-getpropertyvalue g2 "weightat" i)
)
2.0
)
)
)
i (1+i)
)
)
(setq gNurb
(xdge::constructor
"kNurbCurve3d" degree knots pts period)
)
(xdrx-entity-make gNurb)
(xdrx-end)
)
)
)