logo
down
shadow

How to use Math.cos() & Math.sin() properly?


How to use Math.cos() & Math.sin() properly?

Content Index :

How to use Math.cos() & Math.sin() properly?
Tag : actionscript-3 , By : THD
Date : November 21 2020, 07:35 AM

I think the issue was by ths following , The reason is that Math.PI != π.
You can try toFixed(15) to get a precise value.
trace(String(Math.cos(90 * Math.PI / -180).toFixed(15)));
trace(String(Math.sin(180 * Math.PI / -180).toFixed(15)));
trace(String(Math.cos(270 * Math.PI / -180).toFixed(15)));
trace(String(Math.cos(90 * Math.PI / -180).toFixed(15)) == 0);
trace(String(Math.sin(180 * Math.PI / -180).toFixed(15)) == 0);
trace(String(Math.cos(270 * Math.PI / -180).toFixed(15)) == 0);
0.000000000000000
-0.000000000000000
-0.000000000000000
true
true
true

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Math.Sin, Math.Cos and Math.Tan precision and way to display them correctly


Tag : chash , By : ganok_tor
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Basically, it looks like this is expected behavior from Math.Tan. I don't know other languages very well, so I'm not sure if this is normal for floating point Math or specific to the C# implementation. (NOTE: Afterwards, I found that Google's online calculator returns the same suggesting it expected behavior for floating point trig functions, probably related to the fact that pi is irrational and the limitations of the double precision data type)
However, working backwards from this result I am seeing that Math.Atan(// your result); and Math.Atan(double.PositiveInfinity) both return 90 degrees, suggesting this is expected?
var deg = 90.0;
var rads = deg * (Math.PI / 180);
var result = Math.Tan(rads);

if (Double.IsInfinity(result))
    Console.WriteLine("Tan of 90 degrees is Infinity");
else if (Double.IsNaN(result))
    Console.WriteLine("Tan of 90 degrees is Undefined");
else
    Console.WriteLine("Tan of 90 degrees is {0}", result);

Console.WriteLine("Arc Tan of {0} is {1} degrees", double.PositiveInfinity, Math.Atan(double.PositiveInfinity) * 180 / Math.PI);
Console.WriteLine("Arc Tan of {0} is {1} degrees", result, Math.Atan(result) * 180 / Math.PI);
Tan of 90 degrees is 1.63317787283838E+16
Arc Tan of Infinity is 90 degrees
Arc Tan of 1.63317787283838E+16 is 90 degrees
public double ComputeTangent(double angleRads)
{
    if (angleRads == Math.PI/2)
        return double.PositiveInfinity
    if (angleRads == - Math.PI/2)
        return double.NegativeInfinity

    return Math.Tan(angleRads);
}

Java Math.sin Math.cos Math.tan Giving answer in Radian


Tag : java , By : vitorcoliveira
Date : March 29 2020, 07:55 AM
I hope this helps . I was trying to use the Math library in Java where Math.sin(90) gives me result 0.8939966636005579 I search on StackOverflow about this and came to know that the value is) in radian so I used below code to convert it to a degree. , Try double result = Math.sin(Math.toRadians(90))

Using math package (e.g. math.radians, math.tan) on pandas dataframe column


Tag : pandas , By : nickthecook
Date : March 29 2020, 07:55 AM
Hope that helps Two ways we can solve your problem, since you want to pass scalar values to your math functions:
Method 1 using .astype and .apply:
data['new'] = data['col1'].astype(float).apply(math.radians)

   col1 col2       new
0  1.55   10  0.027053
1  2.22   15  0.038746
2  2.22   20  0.038746
3  3.33   30  0.058119
data['new2'] = np.tan(data['col1'].astype(float))

   col1 col2       new       new2
0  1.55   10  0.027053  48.078482
1  2.22   15  0.038746  -1.317612
2  2.22   20  0.038746  -1.317612
3  3.33   30  0.058119   0.190669

Why Math.pow faster then cached Math.pow (var pow = Math.pow)


Tag : javascript , By : enginecrew
Date : March 29 2020, 07:55 AM

An efficient way to implement power function: Why Math.Exp(x * Math.Log(n)) is faster than Math.Pow()?


Tag : chash , By : Cesar Sanz
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Trying to capture stage area using BitmapData
  • Adobe AIR: touch screen doesn't trigger mouse down event correctly
  • Trying to load swf and access FTP-server with Loader in AIR-app
  • How to spawn objects in array without repeating?
  • ActionScript load extern gif animation into htmlText
  • How can I set the draggin box mc 50px from the bottom
  • Tween Blur A Movie Clip Using AS3
  • Actionscript navigation not working
  • Flex Skin addEventListener
  • Move the circle in as3
  • hexagon grid drawing issue
  • Exclude array items from their counterparts
  • IS it possible to test the CameraRoll feature of AIR without using the actual device
  • AS3 functions replacing
  • AS3 cast String as an Object
  • I have two externally loaded SWF files and I would like for each to recognize that the other has loaded or !loaded?
  • Using a loop to create multiple childs of the same bitmap (AS3)
  • AS3 - "parent" of eventlistener
  • Grouping Instances/ Symbols Together
  • Using Embedded Images in a ButtonBar
  • As3 flash error “Cannot access a property or method of a null object reference”
  • How do I iterate through this object properly AS3
  • Trace in FlashBuilder 4.7 not working
  • Bindable setter not called if value of property not changed?
  • Add string value every-time it is called.
  • zip file contents have no data
  • What is an 'action' layer in Adobe Gaming SDK context?
  • Away3D in a Flex Panel component?
  • Why as3 giving me syntax error in a for loop?
  • Why do I get a 0 width for a class instantiated by static variable
  • Cursor movement too fast for code to read
  • Handling Editable Objects
  • Lightweight ComboBox for Action Script 3
  • Is there an AS3 Minify? How do I minify actionscript3?
  • Loading ID3 tags without loading sound in AS3
  • AS3 Stop external swf
  • ActionScript 3 in other runtimes besides Flash?
  • Can we use compiled Haxe swf's swc's in Actionscript as normal libs?
  • AS3: How to dynamically load movieclip from library without exporting in frame 1?
  • AS3: How to get fullscreen and keyboard input?
  • as3 / flex builder - is it possible to change the color of a trace statement?
  • dispatch change value and start tween
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com