Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert point list for grvecs.

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
737 Views, 9 Replies

Convert point list for grvecs.

R2005:

I know this will be easy for you Gurus, but I've searched and have not found anything I can use in the archives.

I have a list of points from a polyline. I want to feed these points to grvecs. As we all know, the points need to be in the form of (list p1 p2 p2 p3 p3 p4 p4 p5) etc.
What's a way to convert my point ilst into this format?

((230.915 -5.04606) (237.383 -9.125) (240.383 -10.8125) (243.383 -12.5)
(246.383 -14.0625) (249.383 -15.5) (252.383 -16.8125) (255.383 -18.0) (258.383
-19.0937))


TIA

Bill
9 REPLIES 9
Message 2 of 10
Anonymous
in reply to: Anonymous

Hi Bill,

This is a modified version of something I use with grdraw. Points can be 2D or 3D.

(defun GrvecsPts (ptlst clr)
(mapcar '(lambda (p1 p2) (grvecs (list clr p1 p2)))
ptlst (cdr ptlst)
)
)

Joe Burke


wrote in message news:4944937@discussion.autodesk.com...
R2005:

I know this will be easy for you Gurus, but I've searched and have not found anything
I can use in the archives.

I have a list of points from a polyline. I want to feed these points to grvecs. As we
all know, the points need to be in the form of (list p1 p2 p2 p3 p3 p4 p4 p5) etc.
What's a way to convert my point ilst into this format?

((230.915 -5.04606) (237.383 -9.125) (240.383 -10.8125) (243.383 -12.5)
(246.383 -14.0625) (249.383 -15.5) (252.383 -16.8125) (255.383 -18.0) (258.383
-19.0937))


TIA

Bill
Message 3 of 10
Anonymous
in reply to: Anonymous

Thanks Joe,

Just what I was looking for.

;-)

Bill
Message 4 of 10
Anonymous
in reply to: Anonymous

Bill, you can use append to merge a list of lists into one list.

(setq lst '((230.915 -5.04606) (237.383 -9.125) (240.383 -10.8125) (243.383 -12.5) (246.383 -14.0625) (249.383 -15.5) (252.383 -16.8125) (255.383 -18.0) (258.383 -19.0937)))

(mapcar 'append lst) --> (230.915 -5.04606 237.383 -9.125 240.383 -10.8125 243.383 -12.5 246.383 -14.0625 249.383 -15.5 252.383 -16.8125 255.383 -18.0 258.383 -19.0937)
Message 5 of 10
Anonymous
in reply to: Anonymous

My pleasure, Bill.

Joe
Message 6 of 10
Anonymous
in reply to: Anonymous

My lisp is a bit rusty, but here is one out of the archives.

;;;Draw closed shape with GRVECS
;;;(setq white 7
;;; doubleTheSize (CreateScaleMatrix 2))
;;;(GrDrawClosedShape '((1 1) (2 1) (2 2) (1 2)) white doubleTheSize)

(defun GrDrawClosedShape (pointList color matrix)
(grvecs
(append
(list color)
(cdr
(apply
'append
(mapcar
'(lambda (pt)
(list pt pt)
)
ptlst
)
)
)
(list (car pointList))
)
matrix
)
)

--
Bobby C. Jones
http://www.acadx.com

wrote in message news:4944937@discussion.autodesk.com...
R2005:

I know this will be easy for you Gurus, but I've searched and have not found
anything I can use in the archives.

I have a list of points from a polyline. I want to feed these points to
grvecs. As we all know, the points need to be in the form of (list p1 p2 p2
p3 p3 p4 p4 p5) etc.
What's a way to convert my point ilst into this format?

((230.915 -5.04606) (237.383 -9.125) (240.383 -10.8125) (243.383 -12.5)
(246.383 -14.0625) (249.383 -15.5) (252.383 -16.8125) (255.383 -18.0)
(258.383
-19.0937))


TIA

Bill
Message 7 of 10
Anonymous
in reply to: Anonymous

Bobby,

Thanks for the code.

How about a peek at the CreateScaleMatrix function. Not found, as far as I can tell,
google searching this NG.

Joe Burke

"Bobby C. Jones" wrote in message
news:4945209@discussion.autodesk.com...
My lisp is a bit rusty, but here is one out of the archives.

;;;Draw closed shape with GRVECS
;;;(setq white 7
;;; doubleTheSize (CreateScaleMatrix 2))
;;;(GrDrawClosedShape '((1 1) (2 1) (2 2) (1 2)) white doubleTheSize)

(defun GrDrawClosedShape (pointList color matrix)
(grvecs
(append
(list color)
(cdr
(apply
'append
(mapcar
'(lambda (pt)
(list pt pt)
)
ptlst
)
)
)
(list (car pointList))
)
matrix
)
)

--
Bobby C. Jones
http://www.acadx.com

wrote in message news:4944937@discussion.autodesk.com...
R2005:

I know this will be easy for you Gurus, but I've searched and have not found
anything I can use in the archives.

I have a list of points from a polyline. I want to feed these points to
grvecs. As we all know, the points need to be in the form of (list p1 p2 p2
p3 p3 p4 p4 p5) etc.
What's a way to convert my point ilst into this format?

((230.915 -5.04606) (237.383 -9.125) (240.383 -10.8125) (243.383 -12.5)
(246.383 -14.0625) (249.383 -15.5) (252.383 -16.8125) (255.383 -18.0)
(258.383
-19.0937))


TIA

Bill
Message 8 of 10
Anonymous
in reply to: Anonymous

I don't think that I ever published any of my matrix code in the newsgroup.
I was working on an article for the site and never finished it.

The first four support routines were posted here long ago by Vladimir,
although the original origin was questioned at the time of the posting.

The next three create some of the more common transformation matrices,
scaling, moving, and rotating about the Z axis. The next routine combines
these individual matrices into a matrix that will perform multiple
transformations, in the event that you wanted to do something crazy like
rotate and scale your grvecs at the same time.

;;; Thanks to Vladimir Nesterovsky
;;;a dot product of the two vectors, u & v
(defun dotprod (u v)
(apply '+ (mapcar '* u v))
)

;;; Thanks to Vladimir Nesterovsky
;;;transpose a matrix
;;;code by doug Wilson
(defun transpose (m)
(apply 'mapcar (cons 'list m))
)

;;; Thanks to Vladimir Nesterovsky
;;;Apply a transformation matrix to a vector
(defun mxv (m v)
(mapcar '(lambda (row) (dotprod row v))
m
)
)

;;; Thanks to Vladimir Nesterovsky
;;;Multiply two matrices
(defun mxm (m q)
(setq q (transpose q))
(mapcar '(lambda (row) (mxv q row))
m
)
)



;;;Create Scale matrix
;;;We add error handling to this matrix to
;;;ensure that we never have a zero scale factor.
;;;It accepts a single scale factor for the
;;;X, Y, & Z or a list of factors in the order
;;;of '(X Y Z).
;;;(CreateScaleMatrix 3.5)
;;;(CreateScaleMatrix '(3 2 1))
(defun CreateScaleMatrix (scale / scaleX scaleY scaleZ)
(mapcar
'(lambda (variableName scaleFactor)
(if (zerop scaleFactor)
(set variableName 1)
(set variableName scaleFactor)
)
)
'(scaleX scaleY scaleZ)
(if (listp scale)
scale
(list scale scale scale)
)
)

(list (list scaleX 0 0 0)
(list 0 scaleY 0 0)
(list 0 0 scaleZ 0)
(list 0 0 0 1)
)
)



;;;Rotate about Z axis
;;;Rotation to be supplied in radians
;;;(CreateRotationAroundZaxisMatrix (* pi 3.33))
(defun CreateRotationAroundZaxisMatrix (Rot)
(list (list (cos Rot) (- (sin Rot)) 0 0)
(list (sin Rot) (cos Rot) 0 0)
(list 0 0 1 0)
(list 0 0 0 1)
)
)



;;;Translate Matrix, or movement
;;;Vector is a list of values
;;;in the order of '(X Y Z) to
;;;define the movement path
;;;(CreateTranslateMatrix '(3 4 0))
(defun CreateTranslateMatrix (Vector)
(list (list 1 0 0 (car Vector))
(list 0 1 0 (cadr Vector))
(list 0 0 1 (caddr Vector))
(list 0 0 0 1)
)
)



;;;Combines multiple Matrices into a single matrix
;;;(BuildTransformationMatrix (list (CreateScaleMatrix 2)
(CreateTranslateMatrix '(2 2 0))))
(defun BuildTransformationMatrix (matrices / TformMatrix)
(foreach matrix matrices
(setq TformMatrix
(if TformMatrix
(mxm TformMatrix matrix)
matrix
)
)
)
)

--
Bobby C. Jones
http://www.acadx.com


"Joe Burke" wrote in message
news:4945330@discussion.autodesk.com...
Bobby,

Thanks for the code.

How about a peek at the CreateScaleMatrix function. Not found, as far as I
can tell,
google searching this NG.

Joe Burke

"Bobby C. Jones" wrote in message
news:4945209@discussion.autodesk.com...
My lisp is a bit rusty, but here is one out of the archives.

;;;Draw closed shape with GRVECS
;;;(setq white 7
;;; doubleTheSize (CreateScaleMatrix 2))
;;;(GrDrawClosedShape '((1 1) (2 1) (2 2) (1 2)) white doubleTheSize)

(defun GrDrawClosedShape (pointList color matrix)
(grvecs
(append
(list color)
(cdr
(apply
'append
(mapcar
'(lambda (pt)
(list pt pt)
)
ptlst
)
)
)
(list (car pointList))
)
matrix
)
)

--
Bobby C. Jones
http://www.acadx.com

wrote in message news:4944937@discussion.autodesk.com...
R2005:

I know this will be easy for you Gurus, but I've searched and have not found
anything I can use in the archives.

I have a list of points from a polyline. I want to feed these points to
grvecs. As we all know, the points need to be in the form of (list p1 p2 p2
p3 p3 p4 p4 p5) etc.
What's a way to convert my point ilst into this format?

((230.915 -5.04606) (237.383 -9.125) (240.383 -10.8125) (243.383 -12.5)
(246.383 -14.0625) (249.383 -15.5) (252.383 -16.8125) (255.383 -18.0)
(258.383
-19.0937))


TIA

Bill
Message 9 of 10
Anonymous
in reply to: Anonymous

Thanks, Bobby.

I'm familiar with Vladimir's mxv and mxm functions. I'll have to study the rest.

Joe Burke


"Bobby C. Jones" wrote in message
news:4945374@discussion.autodesk.com...
I don't think that I ever published any of my matrix code in the newsgroup.
I was working on an article for the site and never finished it.

The first four support routines were posted here long ago by Vladimir,
although the original origin was questioned at the time of the posting.

The next three create some of the more common transformation matrices,
scaling, moving, and rotating about the Z axis. The next routine combines
these individual matrices into a matrix that will perform multiple
transformations, in the event that you wanted to do something crazy like
rotate and scale your grvecs at the same time.

;;; Thanks to Vladimir Nesterovsky
;;;a dot product of the two vectors, u & v
(defun dotprod (u v)
(apply '+ (mapcar '* u v))
)

;;; Thanks to Vladimir Nesterovsky
;;;transpose a matrix
;;;code by doug Wilson
(defun transpose (m)
(apply 'mapcar (cons 'list m))
)

;;; Thanks to Vladimir Nesterovsky
;;;Apply a transformation matrix to a vector
(defun mxv (m v)
(mapcar '(lambda (row) (dotprod row v))
m
)
)

;;; Thanks to Vladimir Nesterovsky
;;;Multiply two matrices
(defun mxm (m q)
(setq q (transpose q))
(mapcar '(lambda (row) (mxv q row))
m
)
)



;;;Create Scale matrix
;;;We add error handling to this matrix to
;;;ensure that we never have a zero scale factor.
;;;It accepts a single scale factor for the
;;;X, Y, & Z or a list of factors in the order
;;;of '(X Y Z).
;;;(CreateScaleMatrix 3.5)
;;;(CreateScaleMatrix '(3 2 1))
(defun CreateScaleMatrix (scale / scaleX scaleY scaleZ)
(mapcar
'(lambda (variableName scaleFactor)
(if (zerop scaleFactor)
(set variableName 1)
(set variableName scaleFactor)
)
)
'(scaleX scaleY scaleZ)
(if (listp scale)
scale
(list scale scale scale)
)
)

(list (list scaleX 0 0 0)
(list 0 scaleY 0 0)
(list 0 0 scaleZ 0)
(list 0 0 0 1)
)
)



;;;Rotate about Z axis
;;;Rotation to be supplied in radians
;;;(CreateRotationAroundZaxisMatrix (* pi 3.33))
(defun CreateRotationAroundZaxisMatrix (Rot)
(list (list (cos Rot) (- (sin Rot)) 0 0)
(list (sin Rot) (cos Rot) 0 0)
(list 0 0 1 0)
(list 0 0 0 1)
)
)



;;;Translate Matrix, or movement
;;;Vector is a list of values
;;;in the order of '(X Y Z) to
;;;define the movement path
;;;(CreateTranslateMatrix '(3 4 0))
(defun CreateTranslateMatrix (Vector)
(list (list 1 0 0 (car Vector))
(list 0 1 0 (cadr Vector))
(list 0 0 1 (caddr Vector))
(list 0 0 0 1)
)
)



;;;Combines multiple Matrices into a single matrix
;;;(BuildTransformationMatrix (list (CreateScaleMatrix 2)
(CreateTranslateMatrix '(2 2 0))))
(defun BuildTransformationMatrix (matrices / TformMatrix)
(foreach matrix matrices
(setq TformMatrix
(if TformMatrix
(mxm TformMatrix matrix)
matrix
)
)
)
)

--
Bobby C. Jones
http://www.acadx.com
Message 10 of 10
Anonymous
in reply to: Anonymous

Thanks Bobby.

I've got most of these already but one or two here I've not seen before.


Bill

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost