0 Members and 1 Guest are viewing this topic.
Cross multiply the x vector with the y vector to get Z
Oh, I found that gile also has a gc:Coplanarp function in the same library found at https://gilecad.azurewebsites.net/Lisp.aspxThis one should answer your question. Code - Auto/Visual Lisp: [Select];; gc:Coplanarp;; Evalue si tous les points de la liste sont coplanaires;;;; Arguments;; pts : une liste de points(defun gc:Coplanarp (pts / norm zlst) (or (null (cdddr pts)) (and (setq norm (gc:Normal3Pts (car pts) (cadr pts) (caddr pts)) zlst (mapcar (function (lambda (p) (caddr (trans p 0 norm)))) pts ) ) (vl-every (function (lambda (z) (equal z (car zlst) 1e-9))) (cdr zlst) ) ) ))
You can also obtain the distance without the use of trans by simply calculating the dot product between the unit normal and a vector from a point in the plane to the given point, e.g.:Code - Auto/Visual Lisp: [Select](defun disttoplane ( pt p1 p2 p3 ) (abs (vxv (vx1 (v^v (mapcar '- p2 p1) (mapcar '- p3 p1))) (mapcar '- pt p1)))) ;; Vector Dot Product - Lee Mac;; Args: u,v - vectors in R^n (defun vxv ( u v ) (apply '+ (mapcar '* u v))) ;; Unit Vector - Lee Mac;; Args: v - vector in R^2 or R^3 (defun vx1 ( v ) ( (lambda ( n ) (if (equal 0.0 n 1e-10) nil (mapcar '/ v (list n n n)))) (distance '(0.0 0.0 0.0) 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))) ))
(defun c:Test () (setq pt1 (list 0.0 0.0 1.0) pt2 (list 100.00 10.00 1.0) pt3 (list 10.00 100.0 1.0) pti (list 200.0 200.0 0.0) ptj (list 200.0 200.0 4.0) ) (princ (strcat "\n. Distance pti to plane: " (rtos (disttoplane pti pt1 pt2 pt3) 2 3))) (princ (strcat "\n. Distance ptj to plane: " (rtos (disttoplane ptj pt1 pt2 pt3) 2 3))) (princ))
You can remove the abs from disttoplane function to get the same result.Note that the plane can be orientated in two ways which will give you a positive or negative output.So above or below might not be what you expect it to be.But if you want to find the difference of pti and ptj, this should work fine.Code - Auto/Visual Lisp: [Select](defun disttoplane ( pt p1 p2 p3 ) (vxv (vx1 (v^v (mapcar '- p2 p1) (mapcar '- p3 p1))) (mapcar '- pt p1)))