CAD programy 4M
Průsečík přímky s plochou
Funkce vrátí bod průsečíku přímky s plochou. Přímka je definována dvěma body, plocha třemi body. Pokud je přímka s plochou rovnoběžná nebo je přímka součástí plochy je zobrazeno oznámení.; Finds LINE and PLANE intersection point (defun C:LP( / lp1 lp2 pp1 pp2 pp3) (setq lp1 (getpoint "\nSelect 1st LINE point: ")) (setq lp2 (getpoint "\nSelect 2nd LINE point: ")) (setq pp1 (getpoint "\nSelect 1st PLANE point: ")) (setq pp2 (getpoint "\nSelect 2nd PLANE point: ")) (setq pp3 (getpoint "\nSelect 3rd PLANE point: ")) (line_x_plane lp1 lp2 pp1 pp2 pp3) ) (defun line_x_plane (lp1 lp2 pp1 pp2 pp3 / lp1x lp1y lp1z lp2x lp2y lp2z pp1x pp1y pp1z pp2x pp2y pp2z pp3x pp3y pp3z ldx ldy ldz a b c d t numerator denominator intersection intx inty intz) ; line variables l ; plane variables p ; delta (vector) values d ; get coordinate values (setq lp1x (car lp1) lp1y (cadr lp1) lp1z (caddr lp1) lp2x (car lp2) lp2y (cadr lp2) lp2z (caddr lp2) pp1x (car pp1) pp1y (cadr pp1) pp1z (caddr pp1) pp2x (car pp2) pp2y (cadr pp2) pp2z (caddr pp2) pp3x (car pp3) pp3y (cadr pp3) pp3z (caddr pp3) ) ; calculate values for plane equation: ax + by + cz + d = 0 ; [a, b, c] is plane normal vector (setq a (- (* (- pp2y pp1y) (- pp3z pp1z)) (* (- pp3y pp1y) (- pp2z pp1z)))) (setq b (- (* (- pp2z pp1z) (- pp3x pp1x)) (* (- pp3z pp1z) (- pp2x pp1x)))) (setq c (- (* (- pp2x pp1x) (- pp3y pp1y)) (* (- pp3x pp1x) (- pp2y pp1y)))) (setq d (* -1 (+ (* a pp1x) (* b pp1y) (* c pp1z)))) ; suppose line equation: ; x = lp1x + ldx * t ; y = lp1y + ldy * t ; z = lp1z + ldz * t ; calculate line vector (setq ldx (- lp2x lp1x) ldy (- lp2y lp1y) ldz (- lp2z lp1z) ) ; substitute line equation to vector equation and calculate t value ; if numerator is 0 then lp1 lies in the plane (setq numerator (+ (* a lp1x) (* b lp1y) (* c lp1z) d)) ; denominator is dot product of 2 vectors; if 0 then line is parallel with the plane (setq denominator (+ (* a ldx) (* b ldy) (* c ldz))) (if (equal denominator 0 0.0001) (progn (if (equal numerator 0 0.0001) (princ "\nLine is coplanar with the plane") (princ "\nLine is parallel with the plane") ) ) (progn (setq t (* -1 (/ numerator denominator))) ; calculate intersection point (setq intx (+ lp1x (* ldx t))) (setq inty (+ lp1y (* ldy t))) (setq intz (+ lp1z (* ldz t))) (setq intersection (list intx inty intz)) ) ) ) (princ)
Soubor ke stažení