Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
kpennell
Posts: 521
Registered: ‎04-14-2004
Message 1 of 17 (506 Views)

Angle from XY plane

506 Views, 16 Replies
06-01-2012 07:38 AM

So I've done a lot of searching this morning on "angles", and I couldn't find anything for getting the "out-of-plane" angle.

 

I'd like the user to pick two points, and return somehow the angle out of plane.

 

Thanks

KP

Distinguished Mentor
_Tharwat
Posts: 599
Registered: ‎07-02-2010
Message 2 of 17 (505 Views)

Re: Angle from XY plane

06-01-2012 07:51 AM in reply to: kpennell

This ... ?

 

(if (and (setq p (getpoint "\n First point :"))
         (setq p1 (getpoint "\n Second point :" p))
)
(print (angle p p1))
)

 

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Contributor
kpennell
Posts: 521
Registered: ‎04-14-2004
Message 3 of 17 (501 Views)

Re: Angle from XY plane

06-01-2012 07:55 AM in reply to: kpennell

This gives the angle "IN" the XY plane.  I need the angle "FROM" the XY plane.

Distinguished Mentor
_Tharwat
Posts: 599
Registered: ‎07-02-2010
Message 4 of 17 (498 Views)

Re: Angle from XY plane

06-01-2012 08:05 AM in reply to: kpennell

Maybe this .... ?

 

(if (and (setq a (getpoint "\n First point :"))
         (setq b (getpoint "\n Second point :" a))
    )
  (progn
    (setq ang (- (angle a b) (angle a (polar a 0.0 (distance a b)))))
    (print (* 180.0 (/ ang pi))
    )
  )
)

 

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Contributor
kpennell
Posts: 521
Registered: ‎04-14-2004
Message 5 of 17 (495 Views)

Re: Angle from XY plane

06-01-2012 08:16 AM in reply to: _Tharwat

This returns the same value, which is the value IN plane, not OUT OF plane or FROM plane

 

Appreciate the efforts though

Distinguished Mentor
_Tharwat
Posts: 599
Registered: ‎07-02-2010
Message 6 of 17 (492 Views)

Re: Angle from XY plane

06-01-2012 08:19 AM in reply to: kpennell

Would you upload an image or a drawing showing your desire of the XY plane 's angle?

____________________________________________________
Get learn and learn and practice , to become experienced guy .
Distinguished Contributor
kpennell
Posts: 521
Registered: ‎04-14-2004
Message 7 of 17 (489 Views)

Re: Angle from XY plane

06-01-2012 08:25 AM in reply to: _Tharwat

It's the same principle as useing the distance command.  When a user picks two points using the distance command there are some values retuned to the command prompt.  I've copied an example based on two random points:

 

Distance = 1'-3 7/16",  Angle in XY Plane = 314.97223515,  Angle from XY Plane = 1.20000000
Delta X = 0'-10 233/256",  Delta Y = -0'-10 235/256",   Delta Z = 0'-0 83/256"

 

I'd like to have the exact value that represents "Angle from XY Plane" returned to a variable somehow.

 

Does this clean up what I'm asking?

 

Thanks

KP

*Expert Elite*
Kent1Cooper
Posts: 5,370
Registered: ‎09-13-2004
Message 8 of 17 (481 Views)

Re: Angle from XY plane

06-01-2012 09:17 AM in reply to: kpennell

kpennell wrote:

So I've done a lot of searching this morning on "angles", and I couldn't find anything for getting the "out-of-plane" angle.

 

I'd like the user to pick two points, and return somehow the angle out of plane.

....


Something like this, perhaps:

 

(setq
  p1 (getpoint "\nPick first point: ")
  p2 (getpoint "\nPick second point: ")
  distinXY (distance (list (car p1) (cadr p1) 0) (list (car p2) (cadr p2) 0))
  deltaZ (- (caddr p2) (caddr p1))
  angfromXYplane (angtos (atan (/ deltaZ distinXY)))
)

 

or, with fewer variables:

 

(setq
  p1 (getpoint "\nPick first point: ")
  p2 (getpoint "\nPick second point: ")
); setq
(angtos
  (atan
    (/
      (- (caddr p2) (caddr p1)); = change in Z
      (distance (list (car p1) (cadr p1) 0) (list (car p2) (cadr p2) 0)); = distance projected in XY plane
    ); /
  ); atan
); angtos

 

I do find that it always returns positive values -- e.g. from 0,0,0 to 1,0,-1 returns 315 degrees.  If you'd rather have that say -45 degrees, you'd need to do some conversion somewhere.

Kent Cooper
*Expert Elite*
Kent1Cooper
Posts: 5,370
Registered: ‎09-13-2004
Message 9 of 17 (469 Views)

Re: Angle from XY plane

06-01-2012 11:00 AM in reply to: Kent1Cooper

Kent1Cooper wrote:
....

I do find that it always returns positive values -- e.g. from 0,0,0 to 1,0,-1 returns 315 degrees.  If you'd rather have that say -45 degrees, you'd need to do some conversion somewhere.


Like this, for instance:

 

(setq
  p1 (getpoint "\nPick first point: ")
  p2 (getpoint "\nPick second point: ")
); setq
(strcat
  (if (< (caddr p2) (caddr p1)) "-" "")
  (angtos
    (atan
      (/
        (abs (- (caddr p2) (caddr p1)))
        (distance (list (car p1) (cadr p1) 0) (list (car p2) (cadr p2) 0))
      ); /
    ); atan
  ); angtos
); strcat

Kent Cooper
Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 10 of 17 (461 Views)

Re: Angle from XY plane

06-01-2012 12:10 PM in reply to: kpennell

For some reasons, I wrote this code to replace native Distance command. It will give you the angle from XY plane among other infos.

(defun C:DI16 (/ *error* lst msg p1 p2 oldzin)

  (defun *error* (msg)
      (and msg
	   (not (eq msg "Function cancelled"))
	   (princ msg)
	   )
    (setvar 'dimzin oldzin)
    (princ)
  )

  (setq oldzin (getvar 'dimzin))
  (setvar 'dimzin 1)
  (and
    (setq p1 (getpoint "\nFirst Point: "))
    (setq p2 (getpoint p1 "\nSecond Point: "))
    (setq lst  (mapcar '- p2 p1)
	  lst1 (mapcar '(lambda (x) (rtos x 2 16)) lst)
    )
    (setq lst1 (cons (angtos (atan (caddr lst) (sqrt (+ (expt (car lst) 2) (expt (cadr lst) 2)))) (getvar 'aunits) 16) lst1))
    (setq lst1 (cons (angtos (atan (cadr lst) (car lst)) (getvar 'aunits) 16) lst1))
    (setq lst1 (cons (rtos (distance p1 p2) 2 16) lst1))
    (mapcar
      '(lambda (x msg)
	 (princ (strcat msg x))
       )
      lst1
      (list "\nDistance            = "
	    "\nAngle in XY Plane   = "
	    "\nAngle from XY Plane = "
	    "\nDelta X             = "
	    "\nDelta Y             = "
	    "\nDelta Z             = "
	   )
    )
  )
  (*error* nil)
  (textscr)
  (princ)
)

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.