Jump to content

Set point coordinates ends up with exponential notation


Recommended Posts

Posted

I have not noticed this problem before...even though I'm using lots of code just like it. These four points define a square:

(defun c:testing ()
(setq a90 (dtr 90.0)
     a270 (dtr 270.0)
     pt10 '(0.0 0.0)
     pt11 (polar pt10 0 48)
     pt12 (polar pt11 a270 48)
     pt13 (polar pt10 a270 48)
       )
(princ)
); end

(defun dtr (x)
 (* pi (/ x 180.0))
); end dtr function

I'm having trouble with this in getting some dimensions entered. The problem I see is that the points come out assigned like this:

pt10 = '(0.0 0.0)

pt11 = '(48.0 0.0)

pt12 = '(48.0 -48.0)

pt13 = '(-1.72675e-014 -48.0)

One would have thought that pt13 would have been '(0.0 -48.0) and I can't help but get this error when trying to dimension:

Error: bad argument type: numberp: (-1.72675e-014 -48.0)
Posted

I dont know exactly reason of that, but here is alternate solution for it,

(setq pt10 (LIST 0 0 0)
     pt11 (polar pt10 (DTR 0) 48)
     pt12 (polar pt11 (DTR 90) 48)
     pt13 (polar pt12 (DTR 180) 48)
       )

Posted

This is to be expected as infinitesimal* errors will creep into arithmetic calculations and accumulate when working with doubles, since numbers can only be expressed to a limited precision dependent on the amount of memory allocated - see this article for more information.

 

However, for your case I see no reason to use the polar function, or the conversion from degrees to radians:

(setq pt10 '( 0.0   0.0)
     pt11 '(48.0   0.0)
     pt12 '(48.0 -48.0)
     pt13 '( 0.0 -48.0)
)

*note that your value of -1.72675e-014 is equal to -0.0000000000000172675 which is very close to zero.

Posted

Thanks Lee,

 

It's a known that the error between the point in the code and the point in the memory is infinitesimally small. But it's keeping me from getting a dimension added to this drawing. I've done lots of these types in the past with no problem but for some reason this set of circumstances is producing this issue.

 

In my process, the user enters some dimensions (a and b) and these are used to locate control points about the drawing. For example, this sets the four corners of a rectangle which outlines the footprint of the assembly:

(setq pt1 '(0.0 0.0)
       pt2 (polar pt1 0 a)
       pt3 (polar pt2 a270 b)
       pt4 (polar pt1 a270 b)
)

I tried assembling the points using strcat but that doesn't quite get it. And would this approach even work? You see the points are assigned based on the numbers input by the users so using polar to assign them is the method I use. Is there another method which could work better and eliminate this rounding error? Note: In this example, dim_a and dim_b are strings having been read in from an external file.

(setq pt2 (strcat "'(" dim_a " 0.0)")
       pt3 (strcat "'(" dim_a " " dim_b ")")
       pt4 (strcat "'(0.0 " dim_b ")")
       )

Posted

Okay, so I corrected the problem I was having with assigning the points using a list...instead of a polar calculation and it now assigns the points to sensible numbers...nothing in exponential notation. But the problem still exists with the dimension...I'll have to do some more digging on this one.

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