add a vector to a list of points

add a vector to a list of points

diegolopezsilanes
Advocate Advocate
1,212 Views
4 Replies
Message 1 of 5

add a vector to a list of points

diegolopezsilanes
Advocate
Advocate

does anyone has a function to add a vector to a list of points?

0 Likes
Accepted solutions (1)
1,213 Views
4 Replies
Replies (4)
Message 2 of 5

john.uhden
Mentor
Mentor

Presuming your points list is in the format '((x1 y1 z1)(x2 y2 z2) etc.) and we call it PNTS, and we have one point as in (setq P '(10 20 0.0), then...

(setq PNTS (append PNTS (list P)))

Although the use of cons can be much faster, as in

(setq PNTS (reverse (cons p (reverse PNTS))))

John F. Uhden

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

@diegolopezsilanes wrote:

does anyone has a function to add a vector to a list of points?



You don't say whether the order of the resulting list matters, i.e. where the added one ends up in relation to what's already in the list.  If it doesn't, just this will do:

(cons newpoint pointlist)

 

But I am a little curious about the terms "vector" and "points."  In AutoCAD, vectors are expressed in the same way as points, but do you mean something different by it?  Or do you, perhaps, mean you want to add a vector [such as an offset] to each point  in an existing list of points?  If that's what you need, this will do it:

(mapcar '(lambda (x) (mapcar '+ x YourVector)) YourPointList)

Kent Cooper, AIA
0 Likes
Message 4 of 5

diegolopezsilanes
Advocate
Advocate

sorry, I was trying to sum the vector to the list of 2d points

0 Likes
Message 5 of 5

Kent1Cooper
Consultant
Consultant

@diegolopezsilanes wrote:

sorry, I was trying to sum the vector to the list of 2d points


 

Is the vector also 2D?  If so, my edit-added suggestion should do.  If it's 3D, and you want the Z coordinate of the vector added to make the 2D points 3D, a little more would need to be done, but it's possible.

Kent Cooper, AIA
0 Likes