rodrigo_sjc_sp Posted June 4, 2013 Posted June 4, 2013 (edited) What better way to store points in a vector and then grab a determinda position: ADD VALUES: maxvector[].add(2761.11 1898.11 0.0) maxvector[].add (3761.12 1538.43 0.0) maxvector[].add(4761.15 2598.58 0.0) RESULT: maxvector[] 0 = (2761.11 1898.11 0.0) 1 = (3761.12 1538.43 0.0) 2 = (4761.15 2598.58 0.0) And then a way to get this value at a given position Ex: (print maxvector[1]) RESULT: (3761.12 1538.43 0.0) Edited June 4, 2013 by rodrigo_sjc_sp Quote
Lee Mac Posted June 4, 2013 Posted June 4, 2013 Use a list: (setq maxvector '( (2761.11 1898.11 0.0) (3761.12 1538.43 0.0) (4761.15 2598.58 0.0) ) ) Then: (nth 1 maxvector) Quote
rodrigo_sjc_sp Posted June 4, 2013 Author Posted June 4, 2013 Lee , Using your sample (setq maxvector '( (2761.11 1898.11 0.0) (3761.12 1538.43 0.0) (4761.15 2598.58 0.0) ) ) How to add a new value(point) in maxvector via lisp ? Quote
Lee Mac Posted June 4, 2013 Posted June 4, 2013 (setq maxvector (cons '(3411.11 9418.11 0.0) maxvector)) PS: Please edit your post and enclose your code with code tags: [highlight][noparse] [/noparse][/highlight] Your code here [highlight][noparse] [/noparse][/highlight] Quote
rodrigo_sjc_sp Posted June 4, 2013 Author Posted June 4, 2013 Lee, how can I get the value using a variable? (setq counting 1) (nth counting maxvector) Quote
Lee Mac Posted June 4, 2013 Posted June 4, 2013 The code you have posted should perform correctly. Quote
rodrigo_sjc_sp Posted June 4, 2013 Author Posted June 4, 2013 ok lee, is that I am using this code and it is returning a wrong position, should be something of the logic then. thank you:ouch: Quote
Lee Mac Posted June 4, 2013 Posted June 4, 2013 Remember that the indices for the nth function are zero-based (i.e. the first item is at index 0), and that the cons function will add a new item to the start of the list. Quote
rodrigo_sjc_sp Posted June 4, 2013 Author Posted June 4, 2013 How do I remove an item from the vector? example.....remove item 3 of vector ex: (maxvector remove 3) Quote
Lee Mac Posted June 4, 2013 Posted June 4, 2013 Consider a 'Remove Nth' function: ;; Remove Nth - Lee Mac ;; Removes the item at the nth index in a supplied list (defun LM:RemoveNth ( n l ) (if (and l (< 0 n)) (cons (car l) (LM:RemoveNth (1- n) (cdr l))) (cdr l) ) ) Or iteratively: ;; Remove Nth - Lee Mac ;; Removes the item at the nth index in a supplied list (defun LM:RemoveNth ( n l / i ) (setq i -1) (vl-remove-if '(lambda ( x ) (= (setq i (1+ i)) n)) l) ) (LM:RemoveNth 3 maxvector) Quote
rodrigo_sjc_sp Posted June 4, 2013 Author Posted June 4, 2013 Thanks lee I made a change in my code using the CDR function (setq maxvector (cdr maxvector)) The result excludes the first item, it was what I needed Thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.