Help computer science? I tried all day and night.

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 3K views
PRAJOL
Messages
5
Reaction score
0

Homework Statement



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

Homework Equations


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;

Homework Statement


Homework Equations


The Attempt at a Solution

 
Last edited by a moderator:
Physics news on Phys.org
Hi PRAJOL! [PLAIN]http://img96.imageshack.us/img96/5725/red5e5etimes5e5e45e5e25.gif

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
 
Last edited by a moderator:
It says undefined reference to draw_vector.
 
yes...you can see above