Author Topic: Calculate Adjacent and opposite of Triangle segments' lengths  (Read 3298 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Calculate Adjacent and opposite of Triangle segments' lengths
« on: October 08, 2013, 08:17:27 AM »
Hello experts .

I am trying to Calculate the adjacent and opposite lengths of a Triangle segments , but I found out the result is short in millimeters which is not correct at all .
This is what I wrote but it's not 100% correct , can anyone correct it for me please ?

Code: [Select]
(setq chord 10.)
(setq a (expt chord 2)
      b (/ a 2.)
      c (sqrt b)
)


Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #1 on: October 08, 2013, 08:26:13 AM »
You are assuming that the triangle has a right-angle... more information is required for a unique solution.

Coder

  • Swamp Rat
  • Posts: 827
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #2 on: October 08, 2013, 08:28:06 AM »
You are assuming that the triangle has a right-angle... more information is required for a unique solution.

Hi Lee ,

Yes it is right angled triangle .
Thanks

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #3 on: October 08, 2013, 08:31:50 AM »
You are assuming that the triangle has a right-angle... more information is required for a unique solution.
Yes it is right angled triangle .

If so, then by Pythagoras your solution is correct:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq x 10.0)
  2. 10.0
  3. _$ (sqrt (* x x 0.5))
  4. 7.07107

Coder

  • Swamp Rat
  • Posts: 827
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #4 on: October 08, 2013, 09:00:40 AM »
You are assuming that the triangle has a right-angle... more information is required for a unique solution.
Yes it is right angled triangle .

If so, then by Pythagoras your solution is correct:
Code - Auto/Visual Lisp: [Select]
  1. _$ (setq x 10.0)
  2. 10.0
  3. _$ (sqrt (* x x 0.5))
  4. 7.07107

I see it is the same result , but the triangle is not closed correctly  , it still opened :-(

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #5 on: October 08, 2013, 09:09:03 AM »
I see it is the same result , but the triangle is not closed correctly  , it still opened :-(

The result shown in the console is only an approximation to 6 significant figures, though the result is still calculated using the maximum precision afforded by a double:
Code - Auto/Visual Lisp: [Select]
  1. _$ (rtos (sqrt (* x x 0.5)) 2 16)
  2. "7.071067811865475"

However, since the true result is likely irrational, any decimal representation will only ever be an approximation.

Coder

  • Swamp Rat
  • Posts: 827
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #6 on: October 08, 2013, 09:20:26 AM »
I see it is the same result , but the triangle is not closed correctly  , it still opened :-(

The result shown in the console is only an approximation to 6 significant figures, though the result is still calculated using the maximum precision afforded by a double:
Code - Auto/Visual Lisp: [Select]
  1. _$ (rtos (sqrt (* x x 0.5)) 2 16)
  2. "7.071067811865475"

However, since the true result is likely irrational, any decimal representation will only ever be an approximation.

Nice , that changed the result to be correct now although the decimal number before was with 4 digits ALSO !!! , and this is correct now .

Code: [Select]
(setq chord 10.)
(setq a (expt chord 2)
      b (/ a 2.)
      c (read (rtos (sqrt b) 2 4))
)

That is strange to be corrected by rtos function  , I did not get it why ! :-o

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #7 on: October 08, 2013, 09:31:06 AM »
Code: [Select]
(setq chord 10.)
(setq a (expt chord 2)
      b (/ a 2.)
      c (read (rtos (sqrt b) 2 4))
)
That is strange to be corrected by rtos function  , I did not get it why ! :-o

The result is always calculated using the maximum available precision (in this case ~ 16 dp); the result returned to the command-line or console is truncated for convenience, however, the variable still contains the result expressed to the full precision.

By using the rtos function to express the result as a string to four decimal places, you have rounded the result.

Coder

  • Swamp Rat
  • Posts: 827
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #8 on: October 08, 2013, 09:37:51 AM »
Great Lee ,

Many thanks professor .  :-)

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Calculate Adjacent and opposite of Triangle segments' lengths
« Reply #9 on: October 08, 2013, 09:49:33 AM »
You're welcome  :-)