Hello all,
i am new here and hope for some help...
I need very very often to know the angle between two surfaces to write cnc programms...
At the moment i draw allways two lines normal to the line between the two surfaces an use then the angle measuring tool.
Works good, faster then bks and dimensioning, but need also time and allways need to delete the lines after...
Is it possible to get a lisp which ask für 1 point on the first surface, 1 point on the other surface and two points on the line between the 2 surfaces? So the lisp know 3 points of each surface and can give out the angle between... Should be allways between 0-180°
So it needs only 4 klicks to get a angle! That would be so great!
Is there a lisp programmer who can make this possible?
Many Thanks!
Ingo
Try this
(defun C:TEST (/ a1 a2 p1 p2) (if (and (setq a1 (getpoint "\nSelect intersection line.\nSelect first point:")) (setq a2 (getpoint a1 "\nSelect second point:")) (not (grdraw a1 a2 7 1)) (setq p1 (getpoint a1 "\nSelect point on first plan:")) (setq p2 (getpoint a1 "\nSelect point on second plan:")) (not (redraw)) (princ "\n") ) (* (/ 180.0 pi) (dihedral_angle a1 a2 p1 p2)) ) ) (defun dihedral_angle (a1 a2 p1 p2) (abs (apply '- (mapcar '(lambda (p) (angle '(0 0 0) (trans (mapcar '- p a1) 0 (mapcar '- a2 a1))) ) (list p2 p1) ) ) ) )
Great choice of coordinate system phanaem
Here is another version, without using trans:
(defun c:pang ( / p1 p2 p3 p4 ) (if (and (setq p1 (getpoint "\nPick 1st point of intersecting line: ")) (setq p2 (getpoint "\nPick 2nd point of intersecting line: " p1)) (setq p3 (getpoint "\nPick point on 1st plane: " p1)) (setq p4 (getpoint "\nPick point on 2nd plane: " p1)) ) (princ (* (/ 180.0 pi) (rem (+ pi pi (dihedral (v^v (mapcar '- p2 p1) (mapcar '- p3 p1)) (v^v (mapcar '- p2 p1) (mapcar '- p4 p1)) ) ) pi ) ) ) ) (princ) ) (defun dihedral ( n1 n2 ) (acos (/ (apply '+ (mapcar '* n1 n2)) (* (distance '(0.0 0.0 0.0) n1) (distance '(0.0 0.0 0.0) n2)) ) ) ) ;; ArcCosine - Lee Mac ;; Args: -1 <= x <= 1 (defun acos ( x ) (if (<= -1.0 x 1.0) (atan (sqrt (- 1.0 (* x x))) x) ) ) ;; Vector Cross Product - Lee Mac ;; Args: u,v - vectors in R^3 (defun v^v ( u v ) (list (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u))) (- (* (car v) (caddr u)) (* (car u) (caddr v))) (- (* (car u) (cadr v)) (* (car v) (cadr u))) ) ) (princ)
Thank you Henrique! - though, it's not quite as elegant as phanaem's solution
Wow! Impresive!
@lee after pick the four points i don´t get an angle in the command line?
@phanaem
works great!
is it possible to get allways the angle between 0-180° ?
is it possible to get only two decimal place?
many thanks!
@hmsilva wrote:Nicely done, phanaem!
Thank you Henrique
From the OP, the output angle "Should be allways between 0-180°"
Henrique
I saw that a second later. This is the correct transformation
(defun dihedral_angle (a1 a2 p1 p2) (rem (+ pi (abs (apply '- (mapcar '(lambda (p) (angle '(0 0 0) (trans (mapcar '- p a1) 0 (mapcar '- a2 a1))) ) (list p1 p2) ) ) ) ) pi ) )
@gringooo wrote:@lee after pick the four points i don´t get an angle in the command line?
Are you sure? (as the program performs fine for me) - if you don't get an angle, what do you get?
after pick all four points i get nothing back...
command abort
i try it with all variation of picking the 4 points
It looks as though only three points have been specified, as the fourth prompt is not shown - here are my results, as an example:
Pick 1st point of intersecting line: Pick 2nd point of intersecting line: Pick point on 1st plane: Pick point on 2nd plane: 30.0 <-- angle
Lee
im sorry Lee!
works great after i reload my drawing!
seems i get allways the right angle!! Gents, your are great!
@phanaem
your solution give me not allways the wished angle back. have a look at the dwg example...
i need the 128,78°
but with your fist solution i get the 231,22°
with your second solution i get the 51,22°
Allways the angle between the two surfaces and between 0-180°
So i don´t have to start a calculator after picking the four points...
thanks!
@gringooo wrote:im sorry Lee!
works great after i reload my drawing!
No problem!
@gringooo wrote:your solution give me not allways the wished angle back. have a look at the dwg example...
i need the 128,78°
but with your fist solution i get the 231,22°
with your second solution i get the 51,22°
Try this modification of phanaem's code (I hope you don't mind phanaem):
(defun c:test ( / a1 a2 nv p1 p2 x1 x2 x3 ) (if (and (setq a1 (getpoint "Select 1st point of intersection line:")) (setq a2 (getpoint "Select 2nd point of intersection line:" a1)) (setq p1 (getpoint "\nSelect point on 1st plane: " a1)) (setq p2 (getpoint "\nSelect point on 2nd plane: " a1)) ) (progn (setq nv (mapcar '- a2 a1) x1 (angle '(0.0 0.0) (trans (mapcar '- p1 a1) 0 nv)) x2 (angle '(0.0 0.0) (trans (mapcar '- p2 a1) 0 nv)) x3 (rem (+ pi pi (- x2 x1)) (+ pi pi)) ) (print (* (/ 180.0 pi) (min (- (+ pi pi) x3) x3))) ) ) (princ) )
wow! works also perfect now!
which of the two cool code should i use now?
i know, not much important, but allways two decimals would be nice?
@gringooo wrote:wow! works also perfect now!
which of the two cool code should i use now?
i know, not much important, but allways two decimals would be nice?
Excellent - all credit to phanaem of course
For 2 d.p.:
(defun c:test ( / a1 a2 nv p1 p2 x1 x2 x3 ) (if (and (setq a1 (getpoint "Select 1st point of intersection line:")) (setq a2 (getpoint "Select 2nd point of intersection line:" a1)) (setq p1 (getpoint "\nSelect point on 1st plane: " a1)) (setq p2 (getpoint "\nSelect point on 2nd plane: " a1)) ) (progn (setq nv (mapcar '- a2 a1) x1 (angle '(0.0 0.0) (trans (mapcar '- p1 a1) 0 nv)) x2 (angle '(0.0 0.0) (trans (mapcar '- p2 a1) 0 nv)) x3 (rem (+ pi pi (- x2 x1)) (+ pi pi)) ) (princ (strcat "\nAngle: " (angtos (min (- (+ pi pi) x3) x3) 0 2))) ) ) (princ) )