Help computer science? I tried all day and night.

In summary, the conversation is about a code that is trying to simulate an acceleration field created by 3 stars. The code is not working and the person is seeking help. There is a discrepancy in the prototype, usage, and definition of the function "draw_vector" where the parameters do not match.
  • #1
PRAJOL
5
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
  • #2
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:
  • #3
It says undefined reference to draw_vector.
 
  • #4
Do your prototype, usage, and definition of draw_vector() match?
That is, do they all have the same parameters?
 
  • #5
yes...you can see above
 
  • #6
I'm afraid they don't...

Perhaps you should copy/paste them below each other to see the difference.
 
  • #7
Where it expects an int you are passing a double.
 

What is computer science?

Computer science is a branch of science that deals with the study of computers and computational systems, including their principles, their hardware and software designs, their applications, and their impact on society.

Why is computer science important?

Computer science is important because it helps us understand and develop the technology that drives our modern world. It also provides us with solutions to complex problems, improves our daily lives, and creates countless job opportunities.

What can I do with a degree in computer science?

A degree in computer science can open up a wide range of career opportunities, such as software development, data analysis, cybersecurity, web development, artificial intelligence, and more. It also provides a strong foundation for pursuing advanced degrees in related fields.

How can I improve my computer science skills?

To improve your computer science skills, you can practice coding regularly, take online courses or attend coding bootcamps, participate in coding challenges and hackathons, and constantly seek to learn new technologies and programming languages.

What is the best way to troubleshoot computer science problems?

The best way to troubleshoot computer science problems is to break down the problem into smaller, manageable parts, and use logical and systematic thinking to identify the root cause. It also helps to consult with others and use available resources, such as online forums and documentation, to find potential solutions.

Back
Top