联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> C/C++编程C/C++编程

日期:2020-07-01 11:04

Your task is to determine collisions between moving circular objects given a starting scenario.

Here is an example:

Three in row

The arrows indicate velocity, and the darkness of the green circles is indicative of the mass of the object.

2.1 Starting scenario

The objects are specified by entering the following information into cin: the mass, radius x/y position, x/y velocity and name of each stone

All the values are in SI units: kg, m, and m/s.

The location information (x/y coordinates in meters) and velocity (x/y coordinates, in meters/second) is the initial values for time t=0t=0.

Here is an example of the input format:

10 1 0  0 1 0 one

30 2 10 0 0.2 0 three

1 1 20 0 0 0 two

Stone three has a mass of 30 kg, a radius of 2 m. It starts out at (10,0)(10,0) with a velocity of (0.2,0)(0.2,0).

2.2 Motion model

The objects travel on a two-dimensional surface. Each object travels in a straight line at a constant velocity. Each object will continue travelling in this direction forever, unless it collides with another object.

2.3 Collision model

Two objects collide at the moment the distance between them becomes equal to the collision distance. For this problem, the collision distance will be the sum of the radii of the colliding stones.

2.3.1 Elastic Collisions

2.3.2 Collision prediction


3 Program

A working version of the program is provided here stones and a partial copy of the source code is provided here stones_template.cpp

The executable is compiled on the devbox, so it must be run there.

You may use all or none of the template file.

3.1 Program behavior

The program starts off by prompting for the starting scenario:

Please enter the mass, radius, x/y position, x/y velocity

and name of each stone

When complete, use EOF / Ctrl-D to stop entering

It will then print out the initial positioning, together with the initial energy of the system and the total momentum:

Here are the initial stones.

one m=10 R=1 p=(0,0) v=(1,0)

three m=30 R=2 p=(10,0) v=(0.2,0)

two m=1 R=1 p=(20,0) v=(0,0)

energy: 5.6

momentum: (16,0)

Finally, the program will print a report about each collision event until there are no more collisions.

This is what the report should look like:

Here are the collision events.


time of event: 8.75

colliding one three

one m=10 R=1 p=(8.75,0) v=(-0.2,0)

three m=30 R=2 p=(11.75,0) v=(0.6,0)

two m=1 R=1 p=(20,0) v=(0,0)

energy: 5.6

momentum: (16,0)


time of event: 17.5

colliding three two

one m=10 R=1 p=(7,0) v=(-0.2,0)

three m=30 R=2 p=(17,0) v=(0.56129,0)

two m=1 R=1 p=(20,0) v=(1.16129,0)

energy: 5.6

momentum: (16,0)

4 The visualizers

4.1 Input visualizer

You can make an image of the starting scenario using visualize (link below)

visualize example2.txt 100 10

The output will be a file example2.png showing the starting positions and velocities. The parameters 100 and 10 are to set the size of the plane to draw (-100 to 100 in this case) and the scaling factor for the arrows.



5 Grading

There will be points for

?correctness

?good program design

?readability

?appropriate use of comments

6 Downloads

Here are all of the relevant files:

?stones the executable

?stones_template.cpp the starter file

?vector2d_class.cpp a partial implementation of the vector2d class

?stones_examples.zip all text files for testing inputs.

?visualize creates image file (PNG) from input scenario

For the executables, you need to make them executable when downloaded, like this in terminal:

chmod 755 stones

chmod 755 visualize


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp