Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
533 Posts
2 Kudos
Registered: ‎04-14-2004
Post 1 of 17

Angle from XY plane

669 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
653 Posts
63 Kudos
Registered: ‎07-02-2010
Post 2 of 17

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
533 Posts
2 Kudos
Registered: ‎04-14-2004
Post 3 of 17

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
653 Posts
63 Kudos
Registered: ‎07-02-2010
Post 4 of 17

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
533 Posts
2 Kudos
Registered: ‎04-14-2004
Post 5 of 17

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
653 Posts
63 Kudos
Registered: ‎07-02-2010
Post 6 of 17

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
533 Posts
2 Kudos
Registered: ‎04-14-2004
Post 7 of 17

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*
6,025 Posts
669 Kudos
Registered: ‎09-13-2004
Post 8 of 17

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*
6,025 Posts
669 Kudos
Registered: ‎09-13-2004
Post 9 of 17

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
Mentor
153 Posts
33 Kudos
Registered: ‎02-06-2007
Post 10 of 17

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

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!