0

So i'm trying to program something for a school project. It needs to stop running when a specific sphere (A) reaches another sphere (B). But it is also allow to hit that sphere (B) within a radius of that sphere (B).

On the other hand, it is not allow to hit certain other sphere's on it's way.

All these sphere's have a specific radius.

IceFire
  • 4,016
  • 2
  • 31
  • 51

1 Answers1

0

I found an answer, You can calculate the magnitude from a vector(radius sphere (B), radius sphere (B)) and if this is larger or equal to the magnitude of the distance between sphere (A) and (B), it will mean that sphere (A) is in the radius of sphere (B).

sphereA = sphere()

sphereB = (sphere(), sphere()) 

with sphereB existing out of multiple sphere B's

for i in range(len(spheres)):
    mag(distance(sphereA.pos,sphereB[i].pos)) <= mag(vector(sphere[i].radius,sphere[i].radius,sphere[i].radius)):
        exit()

you can put a while true before this or something else, so that it keeps checking if your first sphere (A) isn't in the radius of your other sphere's (B)

distance(...) is a function that calculates a vector which is the distance between to vectors *

*vector(x2-x1,y2-y1,z2-z1)