Hi,
You could use these routines.
;; gc:GetVector
;; Retuns the vector from p1 to p2
;;
;; Arguments
;; p1, p2 : 2 points
(defun gc:GetVector (p1 p2) (mapcar '- p2 p1))
;; gc:ScaleVector
;; Multiplies a vector by a scalar
;;
;; Arguments
;; v : a vector
;; s : a number
(defun gc:ScaleVector (v s)
(mapcar (function (lambda (x) (* x s))) v)
)
;; gc:DotProduct
;; Returns the dot product of two vectors
;; Arguments
;; v1, v2 : two vectors
(defun gc:DotProduct (v1 v2) (apply '+ (mapcar '* v1 v2)))
;; gc:IntersLinePlane
;; Returns the point of intersection of the line defined by p1 p2
;; with the plane defined by a point and its normal
;;
;; Arguments
;; p1: a point on the line
;; p2: another point on the line
;; norm: the normal of the projection plane
;; org: a point on the projection plane
;; onSeg : if T, the point of intersection must be on the segment p1, p2
;; if nil, the segment is extended
(defun gc:IntersLinePlane (p1 p2 norm org onSeg / scl)
(if
(and
(/= 0. (setq scl (gc:DotProduct norm (gc:GetVector p1 p2))))
(or
(<= 0.
(setq scl (/ (gc:DotProduct norm (gc:GetVector p1 org)) scl))
1.
)
(not onSeg)
)
)
(mapcar '+ p1 (gc:ScaleVector (gc:GetVector p1 p2) scl))
)
)
;; IntersPoly3dPlane
;; Returns the list of the points of intersection of the polyline 3d
;; with the plane defined by a point and its normal
;;
;; Arguments
;; poly3d: the polyline 3d (ename)
;; norm: the normal of the projection plane
;; org: a point on the projection plane
(defun IntersPoly3dPlane (poly3d norm org / vertex vertices)
(setq vertex (entnext poly3d))
(while (= (cdr (assoc 0 (entget vertex))) "VERTEX")
(if (/= (getpropertyvalue vertex "VertexType") 1)
(setq
vertices (cons (getpropertyvalue vertex "Position") vertices)
)
)
(setq vertex (entnext vertex))
)
(vl-remove
nil
(mapcar '(lambda (p1 p2) (gc:IntersLinePlane p1 p2 norm org T))
vertices
(cdr vertices)
)
)
)