Autor Beitrag
tartare
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

Win XP SP2, WIN Vista Home Professional
Delphi 7/2009, C#, C++(VS 2005 Express)
BeitragVerfasst: Mi 21.02.07 18:47 
Hallo,

ich schreibe gerade ein programm womit sich ein Dreieck berechnen lässt. funktioniert auch ganz gut, außer beim Sinus: Ich habe debugged und Math.Sin(56°) meinte dass das -0.521... ist, habs mit nem Taschenrechner geprüft ist eigentlich 0.829... . Soweit ich weiß kann ein Sinus nicht negativ sein, oder? Woran kann das liegen muss ich das noch irgendwie umrechnen?
Danke im Vorraus...
mfg tartare


Moderiert von user profile iconChristian S.: Topic aus Algorithmen, Optimierung und Assembler verschoben am Mi 21.02.2007 um 17:50

_________________
Ich leb in meiner eigenen Welt, aber das is ok, da kennt man mich.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mi 21.02.07 18:51 
Der Hint für Math.Sin in der IDE sagt's ja schon: "An angle, measured radians." Du musst den Winkel also im Bogenmaß angeben.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8535
Erhaltene Danke: 473

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 21.02.07 18:52 
Doch, sinus kann negativ werden ;-)

Die Ursache deines Problems liegt darin, dass die Routinen im Rechner in aller Regel im Bogenmaß rechnen (ein Kreis = 2pi, auf dem Taschenrechner RAD), und du deinen Taschenrechner bestimmt auf DEG gestellt hast, wo ein voller Kreis 360° sind.
Der Vollständigkeit halber: bei GRAD ist ein voller Kreis 400°. Ein rechter Winkel sind dann 100°.

Such mal nach Deg2Rad oder Rad2Deg oder vergleichbarem - da findet man dann Umrechnungsfunktionen ;-)

_________________
We are, we were and will not be.
tartare Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

Win XP SP2, WIN Vista Home Professional
Delphi 7/2009, C#, C++(VS 2005 Express)
BeitragVerfasst: Mi 21.02.07 19:16 
OK, Danke!!!

Ordnungshalber:
Ich mach das ganze jetz so:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
 private double Cos(double zahl)
        {
            return Math.Cos(zahl * (Math.PI / 180));
        }

        private double Sin(double zahl)
        {
            return Math.Sin(zahl * (Math.PI / 180));
        }

_________________
Ich leb in meiner eigenen Welt, aber das is ok, da kennt man mich.