Jump to content
amir0914

average coordinates

Recommended Posts

amir0914

hi all, i'm beginner in autolisp and i need to a function to get average coordinates of a list coordinate, example :

 

((x1 y1 z1)(x2 y2 z2)(x3 y3 z3) , ..........)

 

average : (x y)

 

is it possible to do this without loop???

Share this post


Link to post
Share on other sites
marko_ribar

(defun average ( lst )
 (mapcar '(lambda ( x ) (/ x (length lst))) (apply 'mapcar (cons '+ lst)))
)

(average '((0.0 1.0 2.0 3.0) (1.0 2.0 3.0 4.0) (2.0 3.0 4.0 5.0) (3.0 4.0 5.0 6.0)))
;; => (1.5 2.5 3.5 4.5)

Share this post


Link to post
Share on other sites
satishrajdev
hi all, i'm beginner in autolisp and i need to a function to get average coordinates of a list coordinate, example :

 

((x1 y1 z1)(x2 y2 z2)(x3 y3 z3) , ..........)

 

average : (x y)

 

is it possible to do this without loop???

 

Are you trying to find our a centroid of coordinate list?

 

If yes then try this http://www.lee-mac.com/polygoncentroid.html

Share this post


Link to post
Share on other sites
amir0914

thank you marko_ribar, big up to you :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×