Poll

getpoint error calculator help

getpoint
0 (0%)
error calculator
0 (0%)

Total Members Voted: 0

Voting closes: August 21, 2020, 11:11:29 PM

Author Topic: getpoint error calculator help  (Read 288 times)

0 Members and 1 Guest are viewing this topic.

leekh

  • Mosquito
  • Posts: 6
getpoint error calculator help
« on: July 22, 2020, 11:11:29 PM »
Code - Auto/Visual Lisp: [Select]
  1. (defun c:t1( / pt1 pt2)
  2.   (princ "\ndist 0.2 chk")
  3.   (setq pt1 (getpoint "\ndown point : "))
  4.   (setq pt2 (getpoint pt1 "\nup point :"))  
  5.   (setq aa (- (- (cadr pt2) (cadr pt1)) 0.2))
  6.   (princ (strcat "\n cal-chk : " (vl-princ-to-string aa)))
  7.   (princ)
  8.   )
  9.  
  10. (defun c:t2( / pt1 pt2)
  11.   (princ "\ndist 0.2 chk")
  12.   (setq pt1 (getpoint "\ndown point : "))
  13.   (setq pt2 (getpoint pt1 "\nup point :"))  
  14.   (setq aa (- (distance pt1 pt2) 0.2))
  15.   (princ (strcat "\n chk : " (vl-princ-to-string aa)))
  16.   (princ)
  17.   )

Code: [Select]
command: t1
dist 0.2 chk
down point:
up point:
 chk : 2.83107e-15

command:
command: t2
dist 0.2 chk
down point:
up point:
 chk : 2.83107e-15

_$ (- (cadr pt2) (cadr pt1))
0.2
_$ (- (- (cadr pt2) (cadr pt1)) 0.2)
2.83107e-15                              <=error      0.0  ok
_$

_$ (distance pt1 pt2)
0.2
_$ (- (distance pt1 pt2) 0.2)
2.83107e-15                               <=error      0.0  ok
_$

_$ (distance pt1 pt2)
0.2
_$ (= (distance pt1 pt2) 0.2)         <-=error  T ok
nil
getpoint or distance error help me


EDIT (John): Added code tags
« Last Edit: July 23, 2020, 11:22:18 AM by John Kaul (Se7en) »

leekh

  • Mosquito
  • Posts: 6
Re: getpoint error calculator help
« Reply #1 on: July 23, 2020, 05:04:43 AM »
command offset 0.2 work

_$ (- (distance pt1 pt2) 0.2)
-1.13798e-14

error

_$ (- (read (vl-princ-to-string (distance pt1 pt2))) 0.2)
0.0

ok

(- (distance pt1 pt2) 0.2)   I don't know why I am getting the error?

VovKa

  • Swamp Rat
  • Posts: 1243
  • Ukraine
Re: getpoint error calculator help
« Reply #2 on: July 23, 2020, 10:56:03 AM »
(rtos (distance pt1 pt2) 2 16)

leekh

  • Mosquito
  • Posts: 6
Re: getpoint error calculator help
« Reply #3 on: July 23, 2020, 09:44:57 PM »
(rtos (distance pt1 pt2) 2 16)

 pt1 pt2 dist = 0.2

 offset 0.2 use

_$ (rtos (distance pt1 pt2) 2 16)
"0.1999999999999993"

why not "0.1999999999999993" is "0.2" ?

Dlanor

  • Bull Frog
  • Posts: 236
Re: getpoint error calculator help
« Reply #4 on: July 24, 2020, 04:27:03 AM »
because you are asking for it to be accurate to 16 significant digits. This is a result of the way floating point math works on computers. GOOGLE "Floating-point error mitigation"

The error is your assumtion that anything that is computed by AutoCAD (which is almost everything) has the value you think it does i.e. the distance between two points is 0.2 where it could be 0.200000000000001 or 0.199999999999998. To all intents and purposes this is 0.2 since (equal 0.199999999999998 0.2 1.0e-13) will return T. AutoCAD's smallest unit is the angstrom (1.0e-10) so the error is insignificant as it is a 1/1000000th of an angstrom. The largest IIRC is the parsec 3.0e16 metres where such an error will be significant, but this is only because of the limited number of computational registers when doing the math, and who apart from astronomers or astrophysicist works with parsecs.


roy_043

  • Water Moccasin
  • Posts: 1799
  • BricsCAD 18
Re: getpoint error calculator help
« Reply #6 on: July 24, 2020, 02:28:55 PM »
@Dlanor:
What you are saying is confusing. Internally AC works with drawing units (DU). They can be considered mm, inches, angstrom etc. A tolerance of 1.0e-13 DU would be relatively the same whatever 1 DU represents.

roy_043

  • Water Moccasin
  • Posts: 1799
  • BricsCAD 18
Re: getpoint error calculator help
« Reply #7 on: July 24, 2020, 02:32:33 PM »
@leekh:
Some decimal numbers cannot be exactly translated to the binary floating point format. Some loss of accuracy therefore has to be taken into account.

leekh

  • Mosquito
  • Posts: 6
Re: getpoint error calculator help
« Reply #8 on: July 26, 2020, 08:42:18 PM »
because you are asking for it to be accurate to 16 significant digits. This is a result of the way floating point math works on computers. GOOGLE "Floating-point error mitigation"

The error is your assumtion that anything that is computed by AutoCAD (which is almost everything) has the value you think it does i.e. the distance between two points is 0.2 where it could be 0.200000000000001 or 0.199999999999998. To all intents and purposes this is 0.2 since (equal 0.199999999999998 0.2 1.0e-13) will return T. AutoCAD's smallest unit is the angstrom (1.0e-10) so the error is insignificant as it is a 1/1000000th of an angstrom. The largest IIRC is the parsec 3.0e16 metres where such an error will be significant, but this is only because of the limited number of computational registers when doing the math, and who apart from astronomers or astrophysicist works with parsecs.

Thank you for your explanation Now I can understand


leekh

  • Mosquito
  • Posts: 6
Re: getpoint error calculator help
« Reply #10 on: July 26, 2020, 08:46:24 PM »
@leekh:
Some decimal numbers cannot be exactly translated to the binary floating point format. Some loss of accuracy therefore has to be taken into account.

Thank you for your explanation Now I can understand