Author Topic: Greater than or equal to...  (Read 12183 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Greater than or equal to...
« Reply #30 on: April 18, 2004, 02:00:49 PM »
This is the way I would approach the problem.
Code: [Select]
;;  returns largest index >=
;;  else return nil
(defun >=index (nu idx1 idx2)
  (if (>= nu (max idx1 idx2)) (max idx1 idx2)))

;;  if between returns the idx closest to
;;  else return nil
(defun >< (nu idx1 idx2)
  (if (and (> nu (min idx1 idx2)) (< nu (max idx1 idx2)))
    (if (> (- idx1 nu) (- idx2 nu)) idx2  idx1)))


;;  if between or = max returns the idx closest to
;;  else return nil
(defun ><=Max (nu idx1 idx2)
  (if (and (> nu (min idx1 idx2)) (<= nu (max idx1 idx2)))
    (if (> (abs(- idx1 nu)) (abs(- idx2 nu))) idx2  idx1)))

;;  if between or = min returns the idx closest to
;;  else return nil
(defun ><=Min (nu idx1 idx2)
  (if (and (>= nu (min idx1 idx2)) (< nu (max idx1 idx2)))
    (if (> (abs(- idx1 nu)) (abs(- idx2 nu))) idx2  idx1)))


(defun diff (nu idx)
  (abs (- nu idx)))

(defun c:test()
  (print "=============")
  (Print  (>< 30 12 54))
  (Print  (>< 10 12 54))
  (print "=============")
  (Print  (><=max 30 12 54))
  (Print  (><=max 54 12 54))
  (Print  (><=max 55 12 54))
  (Print  (><=max 12 12 54))
  (print "=============")
  (Print  (><=min 30 12 54))
  (Print  (><=min 54 12 54))
  (Print  (><=min 11 12 54))
  (Print  (><=min 12 12 54))
  (print "=============")
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Greater than or equal to...
« Reply #31 on: April 18, 2004, 04:30:25 PM »
Ok i did some reading and i think Stig has it right on.

Oh BTW, Cab, Very cool.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org