Jump to content

How measure the angle between two surfaces of 3D solid ?


AIberto

Recommended Posts

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 by AIberto
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

;;

Link to comment
Share on other sites

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" .

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...