Jump to content

Vector multiplications using A/Vlisp


aloy

Recommended Posts

Hi everyone,

Are there built in functions to perform vector transformation ( perhaps using dot and cross products)?. If so, how can I access them.

Thanking in advance,

Aloy

Link to comment
Share on other sites

May want to check the mathematical functions kindly offered by LeeMac.

;; Vector Dot Product  -  Lee Mac
;; Args: u,v - vectors in R^n

(defun vxv ( u v )
   (apply '+ (mapcar '* u v))
)

;; Vector Cross Product  -  Lee Mac
;; Args: u,v - vectors in R^3

(defun v^v ( u v )
   (list
       (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
       (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
       (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
   )
)

Link to comment
Share on other sites

Hi, Tharwat, What I am trying to do is explained in the following link:

 

http://www.surveydrawing.net/find-point-3d-surface.html

 

Since I posted the above I found the following function in the net that might help; have not tested yet to solve equations:

 

(defun C:getNormal ( Point1 Point2 Point3 )

 

(setq Edge1 (vectorDiff Point2 Point1)

Edge2 (vectorDiff Point3 Point1))

 

(setq crossed (cross-product Edge1 Edge2))

(setq normVal (vectorNorm crossed))

(setq unitVector (list (/ (car crossed) normVal)

(/ (cadr crossed) normVal)

(/ (caddr crossed) normVal)))

(eval 'unitVector)

)

 

; vector norm (length)

(defun vectorNorm (Point1)

(eval '(sqrt (+ (expt (car Point1) 2.0)

(expt (cadr Point1) 2.0)

(expt (caddr Point1) 2.0))))

)

 

; vector cross-product

; A x B = (Ay*Bz - Az*By) (Az*Bx - Ax*Bz) (Ax*By - Ay*Bx)

(defun cross-product (Point1 Point2)

(eval '(list (- (* (cadr Point1) (caddr Point2)) (* (caddr Point1) (cadr Point2)))

(- (* (caddr Point1) (car Point2)) (* (car Point1) (caddr Point2)))

(- (* (car Point1) (cadr Point2)) (* (cadr Point1) (car Point2)))))

)

 

; subtract vector

; A - B = (Ax - Bx) (Ay - By) (Az - Bz)

(defun vectorDiff (Point1 Point2)

(eval '(list (- (car Point1) (car Point2))

(- (cadr Point1) (cadr Point2))

(- (caddr Point1) (caddr Point2)) ))

)

Link to comment
Share on other sites

Hi, Mircea,

Thanks for directing to Lee Mac's solutions. As explained to Tharwat, I already got another solution but what you have given appears much more elegant.

Regards,

Aloy

Link to comment
Share on other sites

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...