how do I write a code about 2 3-D spheres colliding? It first asks that I have to entire in an x,y, z coordinate as the two colliding spheres are 3D spheres and it also asks if the distance between their two centers is less than or equal to the sum of their radii. The distance D between 2 spheres with centers (x1, y1, z1) and (x2, y2, z2) is given by the formula: D = √[(x₂ - x₁)² + (y₂ - y₁)² +(z₂ - z₁)²] In this task, you will accept user inputs for the center and radius of two 3D spheres. You will define a class Sphere and create two Sphere objects and initialize them with the user inputs. The objects will also contain built-in methods to calculate their volumes. If the two spheres are identical (two spheres are identical if they have the same center coordinates; you must use the == operator to compare the two Sphere objects), then display a message and exit the program. If they are colliding, display an appropriate message and exit the program. If they are not colliding, display an appropriate message and also display how larger the volume of one sphere is compared to another (‘larger’ refers to the ratio of volume of the bigger sphere to the volume of the smaller sphere). First of all, how do I even start this? Second of all how do I even go about doing this ??
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
how do I write a code about 2 3-D spheres colliding?
It first asks that I have to entire in an x,y, z coordinate as the two colliding spheres are 3D spheres and it also asks if the distance between their two centers is less than or equal to the sum of their radii. The distance D between 2 spheres with centers (x1, y1, z1) and (x2, y2, z2) is given by the formula:
D = √[(x₂ - x₁)² + (y₂ - y₁)² +(z₂ - z₁)²]
In this task, you will accept user inputs for the center and radius of two 3D spheres. You will define a class Sphere and create two Sphere objects and initialize them with the user inputs. The objects will also contain built-in methods to calculate their volumes. If the two spheres are identical (two spheres are identical if they have the same center coordinates; you must use the == operator to compare the two Sphere objects), then display a message and exit the program. If they are colliding, display an appropriate message and exit the program. If they are not colliding, display an appropriate message and also display how larger the volume of one sphere is compared to another (‘larger’ refers to the ratio of volume of the bigger sphere to the volume of the smaller sphere).
First of all, how do I even start this? Second of all how do I even go about doing this ??
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images