AIberto Posted November 30, 2015 Share Posted November 30, 2015 (edited) Hi all How measure the angle between two surfaces of 3D solid ? and How measure the distance(The shortest) between two surfaces of 3D solid ? Edited December 1, 2015 by AIberto Quote Link to comment Share on other sites More sharing options...
lrm Posted November 30, 2015 Share Posted November 30, 2015 The angle between two surfaces can be found by using the following vector equation: angle = arcsin( (Na cross Nb) / (|Na| |Nb|) ) where Na and Nb are the normal vectors of the two surfaces. To get a normal vector of a flat surface assuming p1, p2, and p3 are three, non-collinear points on the surface N = ( vector from p1 to p2 ) cross (vector from p1 to p3) Here's a function I wrote for Autolisp to computer the cross product of two vectors. I'm sure someone will offer a more elegant solution. ;;; Compute the cross product of 2 vectors a and b ;; (defun cross (a b / crs) (setq crs (list (- (* (nth 1 a) (nth 2 b)) (* (nth 1 b) (nth 2 a)) ) (- (* (nth 0 b) (nth 2 a)) (* (nth 0 a) (nth 2 b)) ) (- (* (nth 0 a) (nth 1 b)) (* (nth 0 b) (nth 1 a)) ) ) ;end list ) ;end setq c ) ;end cross ;; ~Lee Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted November 30, 2015 Share Posted November 30, 2015 Alternatively, you could follow the dot-product route to calculate the angle, i.e.: (defun dihedral ( n1 n2 ) (acos (apply '+ (mapcar '* n1 n2))) ) ;; ArcCosine - Lee Mac ;; Args: -1 <= x <= 1 (defun acos ( x ) (if (<= -1.0 x 1.0) (atan (sqrt (- 1.0 (* x x))) x) ) ) Evaluate the above with the unit normal vectors for each plane to return the dihedral angle between the planes - calculate the normal vectors using the cross-product as Lee has described above. Quote Link to comment Share on other sites More sharing options...
AIberto Posted December 1, 2015 Author Share Posted December 1, 2015 lrm & Lee , Thank a lot. Can you give a Example for test ? Thanks! Quote Link to comment Share on other sites More sharing options...
lrm Posted December 1, 2015 Share Posted December 1, 2015 I am not sure how much detail you want for an example. You can create a box with a 45° chamfered edge to verify the calculation. How familiar are you with AutoCAD's VisualLISP? ~Lee Quote Link to comment Share on other sites More sharing options...
lrm Posted December 1, 2015 Share Posted December 1, 2015 The following will calculate the dihedral angle between two planes from 3 points on each of the planes. (defun c:diangle (/ p1 p2 p3 n1 n2 ang) ; calulate dihedral angle between two planes ; from 3 points defining each plane ; get 3 points plane 1 (setq p1 (getpoint "\nSelect point #1 for plane 1") p2 (getpoint "\nSelect point #2 for plane 1") p3 (getpoint "\nSelect point #3 for plane 1") ) (setq n1 (normal3p p1 p2 p3)) ; normal vector plane 1 ; get 3 points plane 2 (setq p1 (getpoint "\nSelect point #1 for plane 2") p2 (getpoint "\nSelect point #2 for plane 2") p3 (getpoint "\nSelect point #3 for plane 2") ) (setq n2 (normal3p p1 p2 p3));normal vector plane 2 ; calculate angle in degrees (setq ang (/ (* 180.0 (dihedral n1 n2)) 3.1415926535)) (princ "\nThe dihedral angle is: ") (princ ang) (princ "°") (princ) ) ;;; unit normal vector from 3 points on plane (defun normal3p (p1 p2 p3 / n d) ; calculate normal vector (setq n (cross (mapcar '- p2 p1) (mapcar '- p3 p1))) ; calculate unit vector normal (setq d (distance '(0 0 0) n)) (setq n (mapcar '/ n (list d d d))) ) ;;; cross product of 2 vectors a and b (defun cross (a b / crs) (setq crs (list (- (* (nth 1 a) (nth 2 b)) (* (nth 1 b) (nth 2 a)) ) (- (* (nth 0 b) (nth 2 a)) (* (nth 0 a) (nth 2 b)) ) (- (* (nth 0 a) (nth 1 b)) (* (nth 0 b) (nth 1 a)) ) ) ;end list ) ;end setq crs ) ;end cross ; Lee Mac's dihedral and acos functions (defun dihedral ( n1 n2 ) (acos (apply '+ (mapcar '* n1 n2))) ) ;; ArcCosine - Lee Mac ;; Args: -1 <= x <= 1 (defun acos ( x ) (if (<= -1.0 x 1.0) (atan (sqrt (- 1.0 (* x x))) x) ) ) ;; Quote Link to comment Share on other sites More sharing options...
AIberto Posted December 2, 2015 Author Share Posted December 2, 2015 The following will calculate the dihedral angle between two planes from 3 points on each of the planes. (defun c:diangle (/ p1 p2 p3 n1 n2 ang) ; calulate dihedral angle between two planes ; from 3 points defining each plane ; get 3 points plane 1 (setq p1 (getpoint "\nSelect point #1 for plane 1") p2 (getpoint "\nSelect point #2 for plane 1") p3 (getpoint "\nSelect point #3 for plane 1") ) (setq n1 (normal3p p1 p2 p3)) ; normal vector plane 1 ; get 3 points plane 2 (setq p1 (getpoint "\nSelect point #1 for plane 2") p2 (getpoint "\nSelect point #2 for plane 2") p3 (getpoint "\nSelect point #3 for plane 2") ) (setq n2 (normal3p p1 p2 p3));normal vector plane 2 ; calculate angle in degrees (setq ang (/ (* 180.0 (dihedral n1 n2)) 3.1415926535)) (princ "\nThe dihedral angle is: ") (princ ang) (princ "°") (princ) ) ;;; unit normal vector from 3 points on plane (defun normal3p (p1 p2 p3 / n d) ; calculate normal vector (setq n (cross (mapcar '- p2 p1) (mapcar '- p3 p1))) ; calculate unit vector normal (setq d (distance '(0 0 0) n)) (setq n (mapcar '/ n (list d d d))) ) ;;; cross product of 2 vectors a and b (defun cross (a b / crs) (setq crs (list (- (* (nth 1 a) (nth 2 b)) (* (nth 1 b) (nth 2 a)) ) (- (* (nth 0 b) (nth 2 a)) (* (nth 0 a) (nth 2 b)) ) (- (* (nth 0 a) (nth 1 b)) (* (nth 0 b) (nth 1 a)) ) ) ;end list ) ;end setq crs ) ;end cross ; Lee Mac's dihedral and acos functions (defun dihedral ( n1 n2 ) (acos (apply '+ (mapcar '* n1 n2))) ) ;; ArcCosine - Lee Mac ;; Args: -1 <= x <= 1 (defun acos ( x ) (if (<= -1.0 x 1.0) (atan (sqrt (- 1.0 (* x x))) x) ) ) ;; Many thanks ,lrm . This code must pick 6 point ...Can only pick 2 face ? How pick 2 face ? maybe can use : Solidedit ---> face--->copy............. At end can remove that face... Maybe need an option. choose Angle is "Acute" or "obtuse" . Quote Link to comment Share on other sites More sharing options...
lrm Posted December 2, 2015 Share Posted December 2, 2015 Alberto, You are welcome. Glad to be of help. ~Lee Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.