Getting wrong results in calculation.

Getting wrong results in calculation.

SidneyAB
Contributor Contributor
968 Views
13 Replies
Message 1 of 14

Getting wrong results in calculation.

SidneyAB
Contributor
Contributor

Hi friends,

 

I having some trouble with an autolisp routine. The concept is to draw steel profiles, I know theres a lot of them around the internet, but I want to write one by myself.

 

The problem is with decimal places, I read a lot of post about this and all say that visualisp will consider the maximum decimal even if I can't see that in variables, but the difference I found is exactly the difference caused by decimal places.

 

For example, Visualisp calculated values are:

 

#slope = 0.1645

#teta = 1.4063

#alfa = 1.7353

#beta = 0.703148

 

On calculator:

 

#slope = 0.16508381

#teta = 1.40571251

#alfa = 1.73588014

#beta = 0.70285626

 

In the attached file red line is hand made and the white section its autolisp with the routine. The real problem come when I try to make the bulge segments because they are not tangent since the slope segment has a different length than the expected. If you zoom in you will see a tiny space between red and white lines.

Thats the calculation I'm using:

 

#slope (atan (/ 166.6 1000))
#teta (- (dr 90) #slope)
#alfa (+ (dr 90) #slope)
#beta (/ #teta 2)

 

Temp.dwg - Steel section test

Estudos Angulos - Reference drawing to find geometric relations

Is there a way to fix this or a better approach?

 

0 Likes
969 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant

And the code?

 

Ok, try this code.

(defun c:test ()

  (defun dr (x) (* x (/ pi 180)))
  
  (setq #slope (atan (/ 166.6 1000))
	#teta (- (dr 90) #slope)
	#alfa (+ (dr 90) #slope)
	#beta (/ #teta 2))

  (princ (rtos #slope 2 8))
  (terpri)
  (princ (rtos #teta 2 8))
  (terpri)
  (princ (rtos #alfa 2 8))
  (terpri)
  (princ (rtos #beta 2 8))
  (princ)
  )

 

No issue here. More digits are still there... just change 8 to say 12 to see them.

0 Likes
Message 3 of 14

Kent1Cooper
Consultant
Consultant

I assume your (dr) function is a degrees-to-radians conversion.  Show us the code for it.

Kent Cooper, AIA
0 Likes
Message 4 of 14

SidneyAB
Contributor
Contributor

Hi,

 

You right the function just converts from degrees to radians, following the code:

 

;;;Converte angulos em graus para radianos.
(defun pg:dr (nod)
(* pi (/ nod 180.0))
)

;;;Converte angulos em radianos para graus.
(defun pg:rd (nor)
(* 180.0 (/ nor pi))
)

 

Thanks

0 Likes
Message 5 of 14

SidneyAB
Contributor
Contributor

Hi,

 

I've attached the code files.

Code with problem start at line 0179 on the file PG Calc V_0_0_6.lsp

The steel section data at line 0008 on the file PG Data V_0_0_5 and variables name at line 1078

And the to draw the profile code start in the line 0053 on file PG Dr V_0_0_2

 

If I do what you did a find the same results as you, but if you make the hand calculations with the values visualisp shows you will find the same difference. Can't figure why?

0 Likes
Message 6 of 14

ВeekeeCZ
Consultant
Consultant

What exact profile is this? How should I set the dialog?

0 Likes
Message 7 of 14

SidneyAB
Contributor
Contributor

Dialog sets on file PGDiag V_0_0_3.

 

Manufacturer catalogue attached, but it dont have all dimensions I need. I found the missing dimensions on an old book.

 

0 Likes
Message 8 of 14

ВeekeeCZ
Consultant
Consultant

I really do think that you are chasing ghosts.

 

If I do what you did a find the same results as you, but if you make the hand calculations with the values visualisp shows you will find the same difference. Can't figure why?

 

Even in the watch window are all real values cut off to just 6 digits, it's just visual representations.

If you don't trust it, create a new variable with (rtos #teta 2 16) and add it to the watch list... and see.

0 Likes
Message 9 of 14

SidneyAB
Contributor
Contributor

Sorry but I can't  agreed with you, couse it's not a ghost when you can see it with your eyes. I never had this king of problem before.

 

May I'm doing something else wrong but I can't find what could be, for a while. I'll will remove all lines relative to this and do it again to see if I can find the error.

 

Thanks anyway.

0 Likes
Message 10 of 14

ВeekeeCZ
Consultant
Consultant

Ok, tell me the first line and variable where you think you lost a precision. Tell me what value it should be and what it is.

 

Use all-in-one code attached.

0 Likes
Message 11 of 14

SidneyAB
Contributor
Contributor

Hi,

 

In the code you've attached problem is between lines 210 and 216. Calculated point is stored on the variable #p1, values for #e and #rp came from line 1691 and are respectively 6.35mm and 2.54mm.

 

The formula to find the lenght was:

#e - LB (from estudo angulos.dwg)

 

At this point, using the values from watch window, visualisp find = 4.19688170mm.

Calculate distance/hand drawing distance = 4.19815569mm.

 

I know it's nothing, but this nothing is making the bulge don't be tangent.

 

I made an update in the code and dwg file to make easy to find the points.

 

Thank you so much to spend your time with my problem.

 

0 Likes
Message 12 of 14

ВeekeeCZ
Consultant
Consultant

Well, IMHO at this point, there is no space to lose the precision. Even the point coords are precise. So if the result is wrong, my bet would be on some bug in the algorithm of calculation. But not going to go through that though.

Good luck! Nice code BTW.

0 Likes
Message 13 of 14

SidneyAB
Contributor
Contributor
I'll rewrite this section of the code and tell you what happen. Thank you.
0 Likes
Message 14 of 14

SidneyAB
Contributor
Contributor
Hi,

I found my error.

(setq #in (/ 166.6 1000)) this line was missing the ATAN the right version is (setq #inc (atan (/ 166.6 1000))).

Now the code is working. Thank you.
0 Likes