@@ -1,8 +1,6 @@ | |||
ISC License: | |||
Copyright (c) 2004-2010 by Internet Systems Consortium, Inc. ("ISC") | |||
Copyright (c) 1995-2003 by Internet Software Consortium | |||
Copyright (c) 2018 Callum David O'Brien | |||
Copyright (c) 2018 Chris O'Brien | |||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | |||
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |||
THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
@@ -1,3 +1,21 @@ | |||
# collisions | |||
# Collisions | |||
Collision simulations in python. | |||
Usage: | |||
```collision [cart | pol] [cart | pol] velocity_1 velocity_2``` | |||
where | |||
- velocity_1 is the velocity of the first particle, in the form | |||
```"r theta"``` if the input vector type is polar, or in the | |||
form ```"x y"``` if the input vector type is cartesian | |||
- velocity_2 is the velocity of the second particle, in the | |||
form ```"r theta"``` if the input vector type is polar, or in | |||
the form ```"x y"``` if the input vector type is cartesian | |||
The program outputs the velocities of the particles after the | |||
collision, in the form specified by the output vector type. | |||
collision simulations in python |
@@ -0,0 +1,96 @@ | |||
import sys | |||
import simulation | |||
def main(): | |||
if (len(sys.argv) != 5): | |||
print("Wrong number of arguments") | |||
sys.exit(1) | |||
(inputVectorType, outputVectorType) = getVectorTypes() | |||
initialVelocities = getVelocities(inputVectorType) | |||
velocitiesAfterCollision = simulation.simulateCollision(initialVelocities, inputVectorType, outputVectorType) | |||
outputVelocities(velocitiesAfterCollision, outputVectorType) | |||
def getVectorTypes(): | |||
inputVectorTypeString = sys.argv[1] | |||
inputVectorType = getVectorTypeFromString(inputVectorTypeString) | |||
outputVectorTypeString = sys.argv[2] | |||
outputVectorType = getVectorTypeFromString(outputVectorTypeString) | |||
return (inputVectorType, outputVectorType) | |||
def getVectorTypeFromString(vectorTypeString): | |||
if (vectorTypeString == "cart" or vectorTypeString == "pol"): | |||
return vectorTypeString | |||
else: | |||
print("Invalid vector type", vectorTypeString) | |||
sys.exit(1) | |||
def getVelocities(inputVectorType): | |||
velocity1String = sys.argv[3] | |||
velocity1 = getVelocityFromString(velocity1String, inputVectorType) | |||
velocity2String = sys.argv[4] | |||
velocity2 = getVelocityFromString(velocity2String, inputVectorType) | |||
return (velocity1, velocity2) | |||
def getVelocityFromString(velocityString, vectorType): | |||
velocityComponentList = velocityString.split(' ') | |||
if (len(velocityComponentList) != 2): | |||
print("Invalid velocity", velocityString) | |||
sys.exit(1) | |||
if (vectorType == "cart"): | |||
xComponent = float(velocityComponentList[0]) | |||
yComponent = float(velocityComponentList[1]) | |||
return (xComponent, yComponent) | |||
elif (vectorType == "pol"): | |||
magnitude = float(velocityComponentList[0]) | |||
direction = float(velocityComponentList[1]) | |||
return (magnitude, direction) | |||
def outputVelocities(velocitiesAfterCollision, vectorType): | |||
(velocity1, velocity2) = velocitiesAfterCollision | |||
print("First particle's velocity:") | |||
printVelocity(velocity1, vectorType) | |||
print() | |||
print("Second particle's velocity:") | |||
printVelocity(velocity2, vectorType) | |||
def printVelocity(velocity, vectorType): | |||
if (vectorType == "cart"): | |||
(xComponent, yComponent) = velocity | |||
print("x:", xComponent) | |||
print("y:", yComponent) | |||
elif (vectorType == "pol"): | |||
(magnitude, direction) = velocity | |||
print("Magnitude:", magnitude) | |||
print("Direction:", direction) | |||
main() | |||
@@ -0,0 +1,7 @@ | |||
import sys | |||
def simulateCollision(initalVelocities, inputVectorType, outputVectorType): | |||
print("simulateCollision(...) is not implemented") | |||
sys.exit(1) | |||