3D polyline intersection with a plane

dar.lombardi
Advocate

3D polyline intersection with a plane

dar.lombardi
Advocate
Advocate

Hi,

How can I find the intersection point between a 3D polyline and a plane?
I read that it is only possible between a line and a plane using the cal function

0 Likes
Reply
Accepted solutions (1)
304 Views
3 Replies
Replies (3)

Kent1Cooper
Consultant
Consultant

A start could be LineIntFace.lsp, >here<, which is about a Line and a 3DFace, but the same approach should be possible for a 3DPolyline segment and a plane.  It would need to step through the 3DPolyline and look at the question segment by segment, and there could of course be more than one intersection.

Kent Cooper, AIA
0 Likes

_gile
Mentor
Mentor
Accepted solution

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

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

dar.lombardi
Advocate
Advocate

I tried it and it works!

thanks, It was very helpful

0 Likes