Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to average complex 3D splines?

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
563 Views, 4 Replies

How to average complex 3D splines?

So I have 10 complex 3D splines and they are all similar in shape but not exact. Is there a way to somehow converge all of my splines into one average spline?

 

Thank you

4 REPLIES 4
Message 2 of 5
Kent1Cooper
in reply to: Anonymous

Do they all have the same number of fit points?  If so, presumably those could be extracted from entity data or the FitPoints VLA Property, and all 10 first ones averaged, all 10 second ones, etc., and put into a list, then that list fed to a new Spline command.  Come to think of it, the way that FitPoints Property works, you could probably average those lists in their entirety, without needing to deal separately with individual points.

Kent Cooper, AIA
Message 3 of 5
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

Do they all have the same number of fit points?  .... the way that FitPoints Property works, you could probably average those lists in their entirety, ....


For instance [minimally tested, and could use a check on whether they all have the same number of Fit Points]:

 

(vl-load-com); if needed

(defun C:SA (/ qua n fitpts1 fitptsSum fitptsAvg); = Spline Average
  (if (setq splss (ssget '((0 . "SPLINE"))))
    (progn ; then
      (setq
        qua (sslength splss)
        n qua
      ); setq
      (repeat qua
        (setq
          fitpts1 (vlax-get (vlax-ename->vla-object (ssname splss (setq n (1- n)))) 'FitPoints)
          fitptsSum
            (if fitptsSum
              (mapcar '+ fitpts1 fitptsSum); then
              fitpts1
            ); if & fitptsSum
        ); setq
      ); repeat
      (setq fitptsAvg (mapcar '(lambda (x) (/ x qua)) fitptsSum))
      (command
        "_.copy" (ssname splss 0) "" '(0 0 0) "@"
        "_.chprop" (entlast) "" "_color" 11 "" ; to distinguish it [edit color # as desired]
      ); command
      (vlax-put (vlax-ename->vla-object (entlast)) 'FitPoints fitptsAvg)
    ); progn
  ); if
); defun

Kent Cooper, AIA
Message 4 of 5
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
.... could use a check on whether they all have the same number of Fit Points....

A more fully-developed version is attached.

Kent Cooper, AIA
Message 5 of 5
Kent1Cooper
in reply to: Kent1Cooper

.... but as it turns out, a Spline that is a result of Offset [of either another Spline or an Elliipse], or one that has been Broken, has nil for the FitPoints property, which throws the whole thing off [the result turns out the same as the first one in the selection].  And one that isn't like that but that was drawn with non-default directional instructions at the ends affects the result [if you pick one that is that way and one that isn't, you get different results depending on which one you picked first].  So I'm working on accounting for those things -- I've got it figured out for the ones that do have Fit Points, averaging both the FitPoints and ControlPoints Properties, but the other issue needs some thought, still....

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost