Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 189043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:08:22+00:00 2026-05-11T16:08:22+00:00

for (iy = 0; iy < h; iy++) { double angy = (camera.fov_y /

  • 0
    for (iy = 0; iy < h; iy++)
    {
        double angy = (camera.fov_y / h) * iy;
        for (ix = 0; ix < w; ix++)
        {
            double angx = (camera.fov_x / w) * ix;
            //output[ix,iy].r = (int)Math.Round(255 * (angy / camera.fov_y);
            //output[ix,iy].b = (int)Math.Round(255 * (angy / camera.fov_y); 
            double tr = (angx / camera.fov_x) * 255D;
            double tb = (angy / camera.fov_y) * 255D;
            Console.Write("({0},{1})",Math.Round(tr),Math.Round(tb));

            output.SetPixel(ix, iy, Color.FromArgb(Convert.ToInt32(tr), 0, Convert.ToInt32(tb)) );
            Console.Write(".");
        }
        Console.WriteLine();
    }

Can anyone see any immediate problems with that code?
The variables tr and tb always evaluate to 0.

I’m happy to provide more information if it is needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:08:22+00:00Added an answer on May 11, 2026 at 4:08 pm

    You haven’t given the types for the other variables – in particular, what are the types of camera.fov_x and camera.fov_y? If they’re both integers, then the lines initializing angx and angy will be evaluated using integer arithmetic.

    This can be fixed by casting one of the operands:

    double angy = ((double) camera.fov_y / h) * iy;
    

    The fovy and fovx variables are already doubles though, this isn’t the problem.

    Could you give a complete example of this, which we can compile and test ourselves?

    EDIT: Koistya Navin’s edit is overkill. You only need one operand of an expression to be a double for the whole thing to be computed using double arithmetic. (It needs to be the right expression though – if you do (a/b) * c and cast c a double, the multiplication will be done with double arithmetic but a/b might still be done as integers.)

    Here’s the listing changed appropriately to make sure double arithmetic is used everywhere it should be:

    // Changed loops to declare the variable, for stylistic purposes
    for (int iy = 0; iy < h; iy++)
    {
        // Changed here - cast camera.fov_y
        double angy = ((double) camera.fov_y / h) * iy;
        for (int ix = 0; ix < w; ix++)
        {
            // Changed here - cast camera.fov_x
            double angx = ((double) camera.fov_x / w) * ix;
            //output[ix,iy].r = (int)Math.Round(255 * (angy / camera.fov_y);
            //output[ix,iy].b = (int)Math.Round(255 * (angy / camera.fov_y); 
            double tr = (angx / camera.fov_x) * 255D;
            double tb = (angy / camera.fov_y) * 255D;
            Console.Write("({0},{1})", Math.Round(tr), Math.Round(tb));
    
            output.SetPixel(ix, iy, Color.FromArgb(Convert.ToInt32(tr), 
                                                   0,
                                                   Convert.ToInt32(tb)) );
            Console.Write(".");
        }
        Console.WriteLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

double a = 18.565 return Math.Round(a,2) ..returns 18.57. For every other number I tried
double d[10]; int length = 10; memset(d, length * sizeof(double), 0); //or for (int
double s_deviation(double data[],int cnt, double mean) { int i; double sum= 0; double sdeviation;
double dval = 1; for (int i = 0; i < Cols; i++) {
double s = 12.20; Console.WriteLine(s); It prints 12.2 but I need it to print
double sqrtIt(double x, double low_guess, double high_guess) { int n = 10; int num
I have a number (double) from int/int (such as 10/3). What's the best way
double volume(double l,double w,double h); double area(double l,double w,double h); int main() { double
My code is: double a = 0.6875; int[] b = new int[5]; for (int
double radius = 5; double area = Math.PI * Math.pow(radius, 2); // System.out.println(area); BigDecimal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.