Jump to content

How can I add several distances to a selection set and find the smallest distance


Recommended Posts

Posted
 (setq dist1 (distance ppup ppdn1)); distance to point
(setq ssdistance(ssadd dist1 ssdistance)); adding to selection set distance
(setq dist2 (distance ppup ppdn2)); distance to point

(setq ssdistance(ssadd dist2 ssdistance)); adding to selection set distance

Posted

Selection sets can only contain entities - you should use a list to store other data.

 

If you are only looking for the minimum of two distances, simply use:

(min (distance ppup ppdn1) (distance ppup ppdn2))

Otherwise, add the distances to a list, and apply the min function across the list:

(setq lst (cons dist1 lst)
     lst (cons dist2 lst)
)
(apply 'min lst)

Or:

(setq lst (cons dist2 (cons dist1 lst)))
(apply 'min lst)

Or:

(setq lst (vl-list* dist2 dist1 lst))
(apply 'min lst)

Posted

Thanks a lot. your advise is perfect.

Next I want to know the smallest distance position of the list .I mean first item or second or which item??

 

 

(To day is the traditional new year day of sri lankan Sinhalese. Happy traditional New year for you.):)

Posted
smallest distance position
this has been asked also recently but if you need to know which section rather than or maybe both minimum do like Lee make a list and use NTH to check the value (nth X lst) is it less than X+1. Running out of time will post example soon.
Posted
Thanks a lot. your advise is perfect.

 

You're welcome!

 

Next I want to know the smallest distance position of the list .I mean first item or second or which item??

 

Given a list of distances assigned to a variable 'lst', there are various ways to do this - here is one example:

(vl-position (apply 'min lst) lst)

 

(To day is the traditional new year day of sri lankan Sinhalese. Happy traditional New year for you.):)

 

Happy 'traditional' New Year to you too! :)

Posted
Thanks a lot. your advise is perfect.

Next I want to know the smallest distance position of the list .I mean first item or second or which item??

 

Sample

(setq lst '(150.23 6854.2 23.52 [b]1.0[/b] 68.65))

(vl-position 0 (vl-sort-i lst '<))
3

or

(vl-position (apply 'min lst) lst)
3 

 

Of course if there are duplicates the results are different

 

(setq lst '(150.23 [b]1.0[/b] 6854.2 23.52 [b]1.0[/b] 68.65))

(vl-position 0 (vl-sort-i lst '<))
[b]4[/b]

(vl-position (apply 'min lst) lst)
[b]1[/b]

(setq lst '(150.23 [b]1.0[/b] 6854.2 23.52 [b]1.0[/b] 68.65 [b]1.0[/b]))

(vl-position 0 (vl-sort-i lst '<))
[b]5[/b]

(vl-position (apply 'min lst) lst)
[b]1[/b]

 

So building the data list and and the type of elements should always be put into consideration.

 

EDIT: I did not see LM's post :lol:

Posted
Sample
(setq lst '(150.23 6854.2 23.52 [b]1.0[/b] 68.65))
(vl-position 0 (vl-sort-i lst '<))
3

 

Be careful - this expression only gives the correct result as a coincidence of the example:

_$ (setq lst '(150.23 6854.2 23.52 1.0 68.65))
(150.23 6854.2 23.52 1.0 68.65)
_$ (vl-position 0 (vl-sort-i lst '<))
3

_$ (setq lst '(150.23 500.1 6854.2 23.52 1.0 68.65))
(150.23 500.1 6854.2 23.52 1.0 68.65)
_$ (vl-position 0 (vl-sort-i lst '<))
3

 

If you wish to use vl-sort-i, I would suggest:

_$ (setq lst '(150.23 500.1 6854.2 23.52 1.0 68.65))
(150.23 500.1 6854.2 23.52 1.0 68.65)
_$ (car (vl-sort-i lst '<))
4

Posted

You are right. took me a while to figure out why that works :lol:

Posted

As usual you guys I had about 15 lines of code and you guys do it with 1 line. The never ending use of VL functions.

Posted

OK Thanks everybody for your helping

codes.

Posted

How can I remove the longest distance from the above list.

Posted
How can I remove the longest distance from the above list.

 

Determine the greatest value using the opposite function (max) with the methods already demonstrated; remove this value using vl-remove or alternatives.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...