TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: BazzaCAD on July 12, 2007, 08:35:28 PM

Title: Angle Precision
Post by: BazzaCAD on July 12, 2007, 08:35:28 PM
How do you increase the angle Precision in LSP?
I'm getting the rotation angle of an ATTRIB.
It returns: AttAng = 1.5708 (i.e. 90 Degrees)
Then I check it...
(> AttAng (* 0.5 pi))
& get T, So I know there's some rounding going on, how do I fix it ? :)
Title: Re: Angle Precision
Post by: MP on July 12, 2007, 08:42:51 PM
What you're seeing is display precision, not internal precision.

Try this --

(rtos attang 2 15)
(rtos (* 0.5 pi) 2 15)

What do you see?

:)
Title: Re: Angle Precision
Post by: Keith™ on July 12, 2007, 08:53:47 PM
Rather than use a decimal approximation of an angle, why not use the angle itself ...

i.e. if you need to make a 90 degree calculation, use

Code: [Select]
(setq AttAng (angtof "90"))

Then when you run this code
Code: [Select]
(= AttAng (* 0.5 pi))

The result is T
Title: Re: Angle Precision
Post by: MP on July 12, 2007, 08:59:48 PM
Keith -- isn't he retrieving the angle from an entity (an attribute) rather than setting it explicitly?

That's how I read it; maybe I'm wrong. It happens.

:)
Title: Re: Angle Precision
Post by: Kerry on July 12, 2007, 09:00:42 PM
..........So I know there's some rounding going on, how do I fix it ? :)


Warm and Fuzzy

(equal expr1 expr2 [fuzz])

(equal MyAng (* PI 0.5) 1.0e-14)  ; << adjust fuzz for  requirements
Title: Re: Angle Precision
Post by: BazzaCAD on July 12, 2007, 10:14:53 PM
Thx for the advice guys.
They're all really helpful.
I'll be getting the angle from an ATTRIB, then setting it if needed.
Basically the overall goal is to make them all Right Reading...
Title: Re: Angle Precision
Post by: Keith™ on July 13, 2007, 08:21:25 AM
Keith -- isn't he retrieving the angle from an entity (an attribute) rather than setting it explicitly?

That's how I read it; maybe I'm wrong. It happens.

:)

You are correct ...
However, either his attribite is not at 90 degrees or he has read the attribute angle from a list and approximated it in the variable.

Insert a block with an attribute at 90 degrees
Check it with this code
Code: [Select]
(=  (cdr (assoc 50 (entget (car (nentsel))))) (* pi 0.5))

It will return T, however if the attribute is not at 90 deg, it will always return nil i.e. if it is at 90.0000001 or anything other than exactly 90 degrees it will return nil.

Use of a fuzz factor in this instance, as Kerry pointed out, will resolve the issue as can be evidenced in this code. Use the same attribute, but rotate it slightly ... say 90.01 deg

Code: [Select]
(equal (cdr (assoc 50 (entget (car (nentsel))))) (* pi 0.5) 0.01 )