1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help computer science? I tried all day and night.

  1. Mar 10, 2012 #1
    1. The problem statement, all variables and given/known data

    What's wrong with code below? I tried all day and night...don't know what's wrong and how to change the code. Help anyone. I have uploaded picture of map which I have to make

    http://www.portmain.com/intro/hw/hw05-field.html [Broken]

    2. Relevant equations



    3. The attempt at a solution

    //File: orbit.cxx
    //Written by Suroj Lamichhane(suroj.lamichhane@colorado.edu)
    //This program opens a large graphics window which simulates the
    //the map of acceleration field created by 3 stars.

    //Directives
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <graphics.h>

    using namespace std;

    //Named Constants
    double const wmax= 2.5*pow(10.0,11.0);
    double const G=6.67*pow(10.0, -11.0);
    int const S=500;

    // Prototypes
    //These functions creates stars at a fixed locations and creates
    // grids. It also changes world coordinates to pixel coordinate
    // and makes vectors in acceleration field.
    void draw_star(double wx,double wy,double radius,int color);
    void draw_vector(double x, double y,double yellow_x,double
    yellow_y,double yellow_m,
    double blue_x,double blue_y,double blue_m,double red_x
    ,double red_y,double red_m);
    int pixel(double wx, double w0, double w1, int p0, int p1);

    double accx(double x, double y, double sx, double sy, double m);

    double accy(double x, double y, double sx, double sy, double m);
    int pixel(double wx, double w0, double w1, int p0, int p1);

    //Function definitions:
    //------------------------------------------------------------------------------
    int main()

    {
    double x, y,yellow_x,yellow_y,yellow_m,
    blue_x,blue_y,blue_m,red_x,red_y,red_m,wx,wy,radius,color;



    initwindow(S,S,"Field of Dreams");
    setfillstyle(SOLID_FILL, WHITE);
    for (y=-wmax; y<wmax; y=y+(wmax/6))
    {
    for(x=-wmax;x<wmax;x=x+(wmax/6))
    {

    draw_vector(x, y,3.0*pow(10.0,10.0),-7.5*pow(10.0,10.0),2.5*pow(10.0,30.0),
    -4.5*pow(10.0,10.0),3.0*pow(10.0,10.0),9.5*pow(10.0,30.0),4.5*pow(10.0,10.0),9.0*pow(10.0,10.0),1.5*pow(10.0,31.0));
    //(3.0e10, -7.5e10)
    //(-4.5e10, +3.0e10)
    //(+4.5e10, +9.0e10)



    }
    draw_star(3.0*pow(10.0,10.0),-7.5*pow(10.0,10.0),5,14);
    draw_star(-4.5*pow(10.0,10.0),3.0*pow(10.0,10.0),7,1);
    draw_star(4.5*pow(10.0,10.0),9.0*pow(10.0,10.0),9,4);
    }


    delay(60000);

    }
    //------------------------------------------------------------------------------
    void draw_star(double wx,double wy,double radius,int color)
    {
    int px=pixel( wx,-1.5, +1.5,0,S);
    int py=pixel( wy,-1.5, +1.5,0,S);
    setfillstyle(SOLID_FILL,color);
    fillellipse(int(px),int(py), int(radius),int(radius));
    setcolor(color);

    }
    //------------------------------------------------------------------------------

    void draw_vector(int x, int y,double yellow_x,
    double yellow_y,double yellow_m,
    double blue_x,double blue_y,double blue_m,
    double red_x,double red_y,double red_m)
    {
    double sx,sy;
    yellow_x=accx(x,y,sx,sy,yellow_m);
    blue_x =accx(x,y,sx,sy,blue_m);
    red_x =accx(x,y,sx,sy,red_m);
    yellow_y=accy(x,y,sx,sy,yellow_m);
    blue_y =accy(x,y,sx,sy,blue_m);
    red_y =accy(x,y,sx,sy,red_m);

    int x1=int (yellow_x+blue_x+red_x);
    int y1=int (yellow_y+blue_y+red_y);



    double length=sqrt((((5.0*pow(10.0,10.0))*x1)*((5.0*pow(10.0,10.0))*x1))
    +(((5.0*pow(10.0,10.0))*y1)*((5.0*pow(10.0,10.0))*y1)));
    if (length<wmax/(7.07107))
    {

    line(x,y,x1,y1);
    setfillstyle(SOLID_FILL,15);
    fillellipse(x,y,2,2);

    }


    }
    //------------------------------------------------------------------------------
    int pixel(double wx, double w0, double w1, int p0, int p1)
    {
    double px;



    px=p0+((wx-w0)*(p1-p0)/(w1-w0));

    return (int(px));
    }
    //------------------------------------------------------------------------------
    double accx(double x, double y, double sx, double sy, double m)
    {
    double dx = (sx - x);
    double dy = (sy - y);
    double denominator = pow(dx*dx + dy*dy, 1.5);
    return G*m*dx/denominator;
    }
    //------------------------------------------------------------------------------
    double accy(double x, double y, double sx, double sy, double m)
    {
    double dx = (sx - x);
    double dy = (sy - y);
    double denominator = pow(dx*dx + dy*dy, 1.5);

    return G*m*dy/denominator;
    1. The problem statement, all variables and given/known data



    2. Relevant equations



    3. The attempt at a solution
     
    Last edited by a moderator: May 5, 2017
  2. jcsd
  3. Mar 10, 2012 #2

    NascentOxygen

    User Avatar

    Staff: Mentor

    Hi PRAJOL! [PLAIN]http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif [Broken]

    Perhaps you should point out what error messages you are generating, or what the program is or isn't doing, otherwise how is anyone to know what part to examine to help you https://www.physicsforums.com/images/icons/icon5.gif [Broken]
     
    Last edited by a moderator: May 5, 2017
  4. Mar 10, 2012 #3
    It says undefined reference to draw_vector.
     
  5. Mar 10, 2012 #4

    I like Serena

    User Avatar
    Homework Helper

    Do your prototype, usage, and definition of draw_vector() match?
    That is, do they all have the same parameters?
     
  6. Mar 10, 2012 #5
    yes.....you can see above
     
  7. Mar 10, 2012 #6

    I like Serena

    User Avatar
    Homework Helper

    I'm afraid they don't...

    Perhaps you should copy/paste them below each other to see the difference.
     
  8. Mar 10, 2012 #7

    NascentOxygen

    User Avatar

    Staff: Mentor

    Where it expects an int you are passing a double.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Help computer science? I tried all day and night.
Loading...