TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JohnK on January 05, 2005, 10:09:27 AM
-
This challange is to interpolate between two knows situations and return the third unknown value. For instance:
Key -- Value
--------------
20 -- 2400
28 -- 3200
Find the value for the key 24 and return it to me.
-
24 = 2800
-
I got my answer ....
-
So when do you think we can start posting our solutions? (What did we decide that one time we were talking about submitting lisp to these challanges.)
-
Well I'd give it a few hours any way.
-
dunno ... it is your thread ...
-
Okay, a few hours it is then.
Give 'er two hours.
-
I thought we said it was up to the original poster of the question.
Hence no directions so I didn't hold back.
-
I guess I was too early AND too late.
-
lol ...No your lisp. You can post the answer. The answer is not that hard to achieve.
-
So, you want a linear or a weighed interpolation? What if the values looked like this?
20 -- 2400
28 -- 3200
30 -- 3205
-
ummm... yes!
:shock: :P
Actualy, I just made mine to handle linear, but if you got one for weighted, thats extra cool!
-
Ok ...2 hours are up .....
(defun interpolate ( @k1 @v1 @k2 @v2 @N )
(+ @v1(*(/(- @v2 @v1)(- @k2 @k1))(- @N @k1)))
)
Syntax:
(interpolate Key1 Value1 Key2 Value2 UnknownKey)
-
mine too. ...Wow same one. (Well i guess that was to be expected. Its just a formula after all huh?!)
;;;
;;; Example:
;;; 20 -- 2400
;;; 28 -- 3200
;;; Find the value for: 24
;;; (interpolate 20 2400 28 3200 24)
;;; -> 2800
(defun interpolate (n1 v1 n2 v2 n3)
(+ (* (/ (- v2 v1) (- n2 n1)) (- n3 n1)) v1))
-
hm... no formula here. Just logic. 24 is halfway between 20 and 28, so 2800 is halfway between 2400 and 3200. :D
-
So you dont think you just followd a formula?
-
hm...I guess so. :D