From: rearman Date: Mon, 13 Apr 2026 19:57:33 +0000 (-0400) Subject: Make average-of-points length agnostic X-Git-Url: https://git.earman.xyz/?a=commitdiff_plain;h=e301d5489aef2fbbf85f38278ebb3ccf72171270;p=lisp%2Fworkenv.git Make average-of-points length agnostic Drop cond for length of one, calculate average based on length of list of points. --- diff --git a/math.lisp b/math.lisp index 31f2ded..70099e8 100644 --- a/math.lisp +++ b/math.lisp @@ -25,18 +25,19 @@ If a 2d point is given, it is converted to 3d with z=0." (cond ((numberp (first points)) points) - ((= (length points) 1) - (first points)) - (t (mapcar #'/ - (list (apply #'+ (mapcar #'first points)) - (apply #'+ (mapcar #'second points)) - (apply #'+ - (mapcar #'(lambda (x) - (if (null (third x)) - 0 - (third x))) - points))) - '(2 2 2))))) + (t (let ((numpoints (length points))) + (mapcar #'/ + (list (apply #'+ (mapcar #'first points)) + (apply #'+ (mapcar #'second points)) + (apply #'+ + (mapcar #'(lambda (x) + (if (null (third x)) + 0 + (third x))) + points))) + (list numpoints + numpoints + numpoints)))))) (defun dot-product-points (apoint bpoint) "Return the dot-product of 3d vectors a and b.