This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Retos/Reto #42 - PUNTO DE ENCUENTRO [Difícil]/python/alberba.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
def colision(posicionA, posicionB, velocidadA, velocidadB): | ||
|
||
xA, yA = posicionA | ||
xB, yB = posicionB | ||
vxA, vyA = velocidadA | ||
vxB, vyB = velocidadB | ||
|
||
if vxA - vxB == 0: | ||
if xA == xB: | ||
tx = 0 | ||
else: | ||
return "Los objetos no se encontrarán." | ||
else: | ||
tx = (xB - xA) / (vxA - vxB) | ||
|
||
if vyA - vyB == 0: | ||
if yA == yB: | ||
ty = 0 | ||
else: | ||
return "Los objetos no se encontrarán." | ||
else: | ||
ty = (yB - yA) / (vyA - vyB) | ||
|
||
if tx == ty: | ||
t = tx | ||
x = xA + vxA * tx | ||
y = yA + vyA * ty | ||
return f"Los objetos colisionan en el punto ({x}, {y}) en un tiempo {t}." | ||
else: | ||
return "Los objetos no se encontrarán." | ||
|
||
print(colision((0, 0), (1, 1), (1, 1), (0, 0))) | ||
|