;
; == Function MeGetCcw
; Determines the direction of 3 points.
; Copyright:
; ©2001 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Type]:
; Pt1 = First point [LIST]
; Pt1 = Second point [LIST]
; Pt3 = Third point [LIST]
; Return [Type]:
; > 1 = ccw [INT]
; > -1 = cw [INT]
; > 0 = Colinear [INT]
; Notes:
; - None
;
(defun MeGetCcw (Pt0 Pt1 Pt2 / X1_Dif X1_Sqr X2_Dif X2_Sqr Y1_Dif Y1_Sqr
Y2_Dif Y2_Sqr)
(setq X1_Dif (- (car Pt1) (car Pt0))
Y1_Dif (- (cadr Pt1) (cadr Pt0))
X2_Dif (- (car Pt2) (car Pt0))
Y2_Dif (- (cadr Pt2) (cadr Pt0))
X1_Sqr (* X1_Dif X1_Dif)
Y1_Sqr (* Y1_Dif Y1_Dif)
X2_Sqr (* X2_Dif X2_Dif)
Y2_Sqr (* Y2_Dif Y2_Dif)
)
(cond
((> (* X1_Dif Y2_Dif) (* Y1_Dif X2_Dif)) 1)
((< (* X1_Dif Y2_Dif) (* Y1_Dif X2_Dif)) -1)
((or (< (* X1_Dif X2_Dif) 0) (< (* Y1_Dif Y2_Dif) 0)) -1)
((< (+ X1_Sqr Y1_Sqr) (+ X2_Sqr Y2_Sqr)) 1)
(0)
)
)
;
; == Function MeMaxInLst
; Searches for the biggest number in a list of numbers.
; Arguments [Type]:
; Lst = List to search [LIST]
; Return [Type]:
; > Biggest Number [REAL] or [INT]
; Notes:
; - None
;
(defun MeMaxInLst (Lst)
(apply 'max Lst)
)
(defun c:test ()
;; (setq p1 nil p2 nil p3 nil p4 nil)
(or p1 (setq p1 (getpoint "\nFirst"))) ; get the points only once
(or p2 (setq p2 (getpoint "\nSecond")))
(or p3 (setq p3 (getpoint "\nThird")))
(or p4 (setq p4 (getpoint "\nForth")))
(setq p4 (list (car p4) (cadr p4))) ; make 2d
;; 2d intersect point of p1-p4 with p2-p3
(setq p1>p2p3 (inters p1 p4 p2 p3 nil))
;; 3d intersect point of p1-p4* with p2-p3
(setq p1>p2p3 (inters
(list (car p1>p2p3) (cadr p1>p2p3) 0.0)
(list (car p1>p2p3) (cadr p1>p2p3) 10.0)
p2 p3 nil)
)
;; get the pick point interset with the plane
(setq px (inters p1 p1>p2p3
(list (car p4) (cadr p4) 0.0)
(list (car p4) (cadr p4) 10.0)
nil)
)
)
(defun c:test3 (/ e1 e2 p1 p2 p3 p4 p5 p1>p2p3 px)
;; (setq p1 nil p2 nil p3 nil p4 nil)
(setq e1 (car (entsel "\nSelect side of triangle")))
(setq e2 (car (entsel "\nSelect Second side of triangle")))
;(setq p3 (entsel "\nThird"))
(or p4 (setq p4 (getpoint "\nSelect point in triangle")))
(setq p4 (trans p4 1 0) ; World
p4 (list (car p4) (cadr p4)) ; make 2d
p1 (cdr (assoc 10 (entget e1)))
p2 (cdr (assoc 11 (entget e1)))
p3 (cdr (assoc 10 (entget e2)))
p5 (cdr (assoc 11 (entget e2))))
;; get the 3 triangle points
(cond
((< (distance p1 p3) 0.0001) (setq p3 p5))
((< (distance p2 p3) 0.0001) (setq p3 p5))
)
;; 2d intersect point of p1-p4 with p2-p3
(setq p1>p2p3 (inters p1 p4 p2 p3 nil))
;; 3d intersect point of p1-p4* with p2-p3
(setq p1>p2p3 (inters
(list (car p1>p2p3) (cadr p1>p2p3) 0.0)
(list (car p1>p2p3) (cadr p1>p2p3) 10.0)
p2 p3 nil)
)
;; get the pick point interset woth the plane
(setq px (inters p1 p1>p2p3
(list (car p4) (cadr p4) 0.0)
(list (car p4) (cadr p4) 10.0)
nil)
)
(setq px (trans px 0 1))
(command ".point" "non" px)
px
)
Take the equation of the plane and the equation of the line
(parametrically), and solve them as a system of equations.
For instance...
plane: 2x +4y +5z = 0
line:
x=t
y=2t
z=3t+5
then you plug in x y and z into the plane's equation, and solve for t...
2*t + 4*2*t + 5*3*t + 5*5 = 0
25*t = -25
t = -1
then, once you know t, just plug it in to the line's equation to find the
point of intersection:
x = -1
y = 2*-1 = -2
z = 3*-1 + 5 = 5 - 3 = 2
so the intersection is at <-1,-2,2>. Unless I messed something up, which is
entirely possible...
User picks the points of the 3d triangle. p1 p2 p3
Then picks a point within the triangle. p4
Using the inters function I get the 2d intersect with p1-p4 and p2-p3 -> p1>p2p3 snip...
I didn't say p1 & p4 intersect.Neither have I, Alan.
I didn't say p1 & p4 intersect.
Here is an explanation.
The average z would only apply to the center of the triangle.:oops:
;; return t if p is inside of 3 points
(defun inside (p p1 p2 p3 / sideof)
;;D. C. Broad, Jr.
;;(sideof <ray-origin> <another-point-on-ray> <point-to-be-tested>)
(defun sideof (p1 p2 p / r)
(setq r
(cond
((equal p1 p 1e-10) 0)
(t (sin (- (angle p1 p) (angle p1 p2))))
)
)
(if (equal r 0 1e-10)
0
(if (minusp r) -1 1) ; CAB modified
)
)
;;return values
;;negative = point is to the right side of the ray
;;0 = point is on the ray
;;otherwise point is on the left side of the ray.
;;P1 should not equal P2 for meaningful results.
(defun 2d (pt) (list (car pt) (cadr pt)))
(setq p (2d p)
p1 (2d p1)
p2 (2d p2)
p3 (2d p3)
)
(= (sideof p1 p2 p) (sideof p2 p3 p) (sideof p3 p1 p))
)
;
; -- MeIsInTriangle
; Checks a point for inside a triangle.
; Arguments [Typ]:
; Pnt = Point to test [LIST]
; Pta = First triangle point [LIST]
; Ptb = Second triangle point [LIST]
; Ptc = Third triangle point [LIST]
; Return [Typ]:
; > True if inside [BOOLEAN]
; > False if outside [BOOLEAN]
; Notes:
; - Triangle points must be ccw
; - Points on edge are inside
;
(defun MeIsInTriangle (Pnt Pta Ptb Ptc / CroAbp CroBcp CroCap)
(setq CroAbp (-
(* (- (car Ptc) (car Ptb)) (- (cadr Pnt) (cadr Ptb)))
(* (- (cadr Ptc) (cadr Ptb)) (- (car Pnt) (car Ptb)))
)
CroCap (-
(* (- (car Ptb) (car Pta)) (- (cadr Pnt) (cadr Pta)))
(* (- (cadr Ptb) (cadr Pta)) (- (car Pnt) (car Pta)))
)
CroBcp (-
(* (- (car Pta) (car Ptc)) (- (cadr Pnt) (cadr Ptc)))
(* (- (cadr Pta) (cadr Ptc)) (- (car Pnt) (car Ptc)))
)
)
(and (>= CroAbp 0) (>= CroCap 0) (>= CroBcp 0))
)