Mentions légales du service

Skip to content
Snippets Groups Projects
Commit cd2a6628 authored by SANCHEZ Victor's avatar SANCHEZ Victor
Browse files

little change in the measurement.py file

parent 3959ba01
No related branches found
No related tags found
No related merge requests found
...@@ -71,24 +71,27 @@ def measure_distance(p1, p2, simulation=None): ...@@ -71,24 +71,27 @@ def measure_distance(p1, p2, simulation=None):
if simulation is None: if simulation is None:
raise UserWarning('The distance measurement between an object and a position needs the simulation') raise UserWarning('The distance measurement between an object and a position needs the simulation')
# In case the object is given in firt or second position
if isinstance(p1, mpi_sim.Object) : if isinstance(p1, mpi_sim.Object) :
_object = p1 _object = p1
point = p2 _point = p2
else : else :
_object = p2 _object = p2
point = p1 _point = p1
distance = np.inf distance = np.inf
point_a = None point_a = None
point_b = None point_b = None
# Creating an object to measure the distance from
fake_dot_obj = mpi_sim.objects.RoundTable( fake_dot_obj = mpi_sim.objects.RoundTable(
position=point, position=_point,
orientation=0, orientation=0,
radius = 0.000001, radius = 0.000001,
) )
simulation.add_object(fake_dot_obj) simulation.add_object(fake_dot_obj)
# Measure the min distance for each bodies and each fixture
for body_a in fake_dot_obj.box2d_bodies: for body_a in fake_dot_obj.box2d_bodies:
for fixture_a in body_a.fixtures: for fixture_a in body_a.fixtures:
...@@ -114,8 +117,12 @@ def measure_distance(p1, p2, simulation=None): ...@@ -114,8 +117,12 @@ def measure_distance(p1, p2, simulation=None):
distance = b2_dist_info.distance distance = b2_dist_info.distance
point_a = np.array(b2_dist_info.pointA) point_a = np.array(b2_dist_info.pointA)
point_b = np.array(b2_dist_info.pointB) point_b = np.array(b2_dist_info.pointB)
# Remove the fake object from simulation
simulation.remove_object(fake_dot_obj) simulation.remove_object(fake_dot_obj)
# Correct the distance measurement w.r.t to its radius
distance += 0.000001
return DistanceInfo(distance, point_a, point_b) return DistanceInfo(distance, point_a, point_b)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment