Recent

Author Topic: Question about Round func.  (Read 2638 times)

Ilya83

  • Newbie
  • Posts: 6
Question about Round func.
« on: December 30, 2024, 10:42:27 pm »
FPC 3.2.2

I'm trying to draw Line with angle and I get weird values:

Quote
dx:= 200+round(cos(90)*200);
dy:= 200-round(sin(90)*200);

Gives: dx=110, dy=21

It should be: dx= 200, dy= 0

Am I wrong?

speter

  • Sr. Member
  • ****
  • Posts: 359
Re: Question about Round func.
« Reply #1 on: December 30, 2024, 10:49:29 pm »
Sin and Cos use Radians not Degrees.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Ilya83

  • Newbie
  • Posts: 6
Re: Question about Round func.
« Reply #2 on: December 30, 2024, 11:32:24 pm »
Quote
ShowMessage(FloatToStr(RadToDeg(cos(90)))); 

Gives: -25.67 ?

jamie

  • Hero Member
  • *****
  • Posts: 6798
Re: Question about Round func.
« Reply #3 on: December 30, 2024, 11:34:03 pm »
no
you must convert the value to COS and SIN

COS(DegreeToRad(90))

etc

The only true wisdom is knowing you know nothing

Ilya83

  • Newbie
  • Posts: 6
Re: Question about Round func.
« Reply #4 on: December 31, 2024, 08:43:56 am »
Quote
ShowMessage(FloatToStr(cos(DegToRad(90)))); 

Gives: -2.71...E^-20

DragoRosso

  • New Member
  • *
  • Posts: 42
Re: Question about Round func.
« Reply #5 on: December 31, 2024, 09:14:49 am »
Code: Pascal  [Select][+][-]
  1.   ShowMessage(SimpleRoundTo(Cos(DegToRad(90)), -21).toString);
  2.   ShowMessage(SimpleRoundTo(Cos(DegToRad(90)), -8).toString);          

dseligo

  • Hero Member
  • *****
  • Posts: 1458
Re: Question about Round func.
« Reply #6 on: December 31, 2024, 12:31:23 pm »
Quote
ShowMessage(FloatToStr(cos(DegToRad(90)))); 

Gives: -2.71...E^-20

And what does ShowMessage(FloatToStr(200 + cos(DegToRad(90)))); gives you?
I mean that is what you want it, isn't it?

Ilya83

  • Newbie
  • Posts: 6
Re: Question about Round func.
« Reply #7 on: December 31, 2024, 01:20:10 pm »
Quote
I mean that is what you want it, isn't it?

It's perfect! Thanks everyone!

 

TinyPortal © 2005-2018