Jump to content
yajis_narif

distance between points in lines ?

Recommended Posts

yajis_narif

hii

i have a drawing with 4 lines of points (each line of points with the same Y) . i have the coordinate of the points of each line in a list and all the lists in a list .

so now i want to calculate the disatnce between points of each list knowing that the number of points in lines may change and may not be equal as follows :

. . . . .

. . . . .

. . . .

. . .

 

 

so i've created a lisp that can measure the distance but the only problem is that i can calculate the distance only if the lines have the same number of points.

plzz help me ans again sorry my english is bad

Share this post


Link to post
Share on other sites
Ahankhah

Could you post your code?

Share this post


Link to post
Share on other sites
pBe
hii

iso i've created a lisp .....

 

where is it? :)

Share this post


Link to post
Share on other sites
yajis_narif

(defun LM:GroupByFoo ( lst foo )
 (if lst
   (cons
     (cons (car lst)
       (vl-remove-if-not '(lambda ( x ) (foo (cadr lst) x)) (cdr lst))
     )
     (LM:GroupByFoo (vl-remove-if '(lambda ( x ) (foo (car lst) x)) (cdr lst)) foo)
   )
 )
)

(defun c: test (all /)     
(setq lall(length all))
(setq f -1)
(setq sorty (list))
       (while ( < (setq f (1+ f)) lall)
(setq allc (vl-sort                                   
   (LM:GroupByFoo (nth f all)
    (lambda ( a b ) (equal (cadr a) (cadr b)))
   )
 '(lambda ( a b ) (< (cadar a) (cadar b)))
 )
)
(setq sorty (append sorty (list allc)))  
)
(setq ls (length sorty))
(setq lallc(length allc))

(setq n -1)
(setq sortall(list))
(while ( <(setq n (1+ n)) ls)
(setq m -1)
(setq sortx (list))
(while ( < (setq m (1+ m)) lallc)

(setq xx0 (vl-sort (nth m (nth n sorty))
(function (lambda (e1 e2)
( < (car e1) (car e2)) ) ) ))
(setq sortx (append sortx (list xx0)))            
)
(setq sortall(append sortall (list sortx)))          
)  
(setq Ldie(length sortall))
(setq di1 (nth 0 sortall))
(setq l1 (length (nth 0 sortall)))
(setq ty -1)
(setq lleny (list))
(while (< (setq ty (1+ ty)) l1)

(setq lleny (append lleny (list (length (nth ty di1)))))    
)
(princ lleny)

(setq diste (list))
(setq dislist (list))

(setq t -1)
(while ( <(setq t (1+ t)) l1)                                    
(setq r -1)
(setq q 0)
(setq diste (list))         
(while (and (< (setq r(1+ r)) 4)( < (setq q (+ 1 q)) 4))   

(setq di (distance (nth r (nth t (nth 0 sortall))) (nth q (nth t (nth 0 sortall)))))
(setq diste (append diste ( list di)))

)
(setq dislist(append dislist (list diste)))  
                      
)

 

thanks

Share this post


Link to post
Share on other sites
Lee Mac

The 'GroupByFoo' looks incorrect, check the one I supplied here.

Share this post


Link to post
Share on other sites
Ahankhah

1- In your code one closing paranthesis is needed at the very end of file.

2- It is forbidden in AutoLISP to assign a name to a function or variable with spaces, so c: test is wrong.

3- A command defined by AutoLISP can not have any arguement, your command: test has: (defun c: test (all /) ...

 

I am checking the code.

Share this post


Link to post
Share on other sites
yajis_narif

i just gives you a part of the code and sorry for the c: it's a mistake my bad :lol:

thank you

Share this post


Link to post
Share on other sites
BlackBox

3- A command defined by AutoLISP can not have any arguement, your command: test has: (defun c: test (all /) ...

 

I believe what Ahankah is trying to say, is that in order to supply an argument to your function you might instead use:

 

(defun test (all / )
 ;; <-- Your code here

 

Example syntax: (test all)

Share this post


Link to post
Share on other sites
Ahankhah

Renderman, you are right. English isn't my native language, I live in Iran, but you live Somewhere between Civil 3D and Maya, which means your language isn't Persian.

Share this post


Link to post
Share on other sites
BlackBox
Renderman, you are right. English isn't my native language, I live in Iran, but you live Somewhere between Civil 3D and Maya, which means your language isn't Persian.

 

Ahankhah, I mean no offense to you, my friend. :)

 

I simply tried to provide an example to your correct statement, as when I began programming LISP, I would not have understood fully. For me, sometimes 'seeing' an example helps me to understand.

 

I assure you, your English is far superior to my Persian. :thumbsup:

Share this post


Link to post
Share on other sites
Ahankhah

Renderman, I just wanted to confess that I know my English isn't so good.

I respect you as one of the active members of CADTutor. I learn much in this forum and thank you and all other friends for this.

Share this post


Link to post
Share on other sites
yajis_narif

hello anyone can help me plzzz :lol:

Share this post


Link to post
Share on other sites
Tharwat
hello anyone can help me plzzz :lol:

 

You still looking for a help .:)

 

What's the issue buddy .

Share this post


Link to post
Share on other sites
yajis_narif

i have a drawing with 4 lines of points (each line of points with the same Y) . i have the coordinate of the points of each line in a list and all the lists in a list .

so now i want to calculate the disatnce between points of each list knowing that the number of points in lines may change and may not be equal as follows :

. . . . .

. . . . .

. . . .

. . .

 

thanks tharwat

Share this post


Link to post
Share on other sites
Tharwat

You want to calculate the distance from the list or from the distance between points ?

Share this post


Link to post
Share on other sites
yajis_narif

yes i want to calculate the distance between points in every line

Share this post


Link to post
Share on other sites
Lee Mac

If your point list is in the format:

 

(
 (<Point1> <Point2> ... <PointN>)
 (<Point1> <Point2> ... <PointN>)
 ...
 (<Point1> <Point2> ... <PointN>)
)

 

then perhaps:

 

(defun test ( mainlist )
 (mapcar
   (function
     (lambda ( sublist )
       (mapcar 'distance sublist (cdr sublist))
     )
   )
   mainlist
 )
)

Share this post


Link to post
Share on other sites
yajis_narif

yes exactly my list is in that format and i want to calculate the distance between ( and ) ,( and )...... and )

Share this post


Link to post
Share on other sites
Lee Mac

Try my test code...

Share this post


Link to post
Share on other sites
yajis_narif

thank you lee Mac it worked thanks for your help actually i was stuck in it for 3 days

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

×