954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ARGH!! this is so lame: int to double

Please help with the following code, I tried casting, and the such but this keeps getting rounded

public void rotacion(Point[] pts, int degreesIncr)
    {
        
        //here... I tried casting all combinations, even casted each variable, each 
        //number, and nothing, radians keeps being integral. but if I sustitute a 
        // constant number (e.g 80) radians is double, and I dont understand why. 
        //so silly this is.
        double radians =(degreesIncr)*(Math.PI / 180); 
        double sinAngle = Math.Sin(radians);
        double cosAngle = Math.Cos(radians);
        MessageBox.Show(radians.ToString() + "," + sinAngle.ToString() + "," + cosAngle.ToString());
        for (int i = 0; i < pts.Length; ++i)
        {
            pts[i].X = (int)(pts[i].X * (cosAngle) - pts[i].Y * (sinAngle));
            pts[i].Y = (int)(pts[i].Y * (cosAngle) + pts[i].X * (sinAngle));
        }
namehere05
Light Poster
25 posts since Dec 2008
Reputation Points: 11
Solved Threads: 1
 

Have you tried passing degreesIncr as a double instead of an int?

LevyDee
Posting Whiz in Training
260 posts since Mar 2010
Reputation Points: 13
Solved Threads: 25
 

Also, change the 180 to 180.0.
The compiler interprets 180 as an integer and 180.0 as a double.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

Oh, its working now, the problem was in the parameter, I was not passing the intended variable, I feel bad but I was desesperate, maybe next time Ill have some rest first and check the code later before posting, thanks

namehere05
Light Poster
25 posts since Dec 2008
Reputation Points: 11
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You