env3D.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # this is the three dimensional configuration space for rrt
  2. # !/usr/bin/env python3
  3. # -*- coding: utf-8 -*-
  4. """
  5. @author: yue qi
  6. """
  7. import numpy as np
  8. def getblocks():
  9. # AABBs
  10. block = [[3.10e+00, 0.00e+00, 2.10e+00, 3.90e+00, 5.00e+00, 6.00e+00],
  11. [9.10e+00, 0.00e+00, 2.10e+00, 9.90e+00, 5.00e+00, 6.00e+00],
  12. #[1.51e+01, 0.00e+00, 2.10e+00, 1.59e+01, 5.00e+00, 6.00e+00],
  13. #[1.00e-01, 0.00e+00, 0.00e+00, 9.00e-01, 5.00e+00, 3.90e+00],
  14. #[6.10e+00, 0.00e+00, 0.00e+00, 6.90e+00, 5.00e+00, 3.90e+00],
  15. [1.21e+01, 0.00e+00, 0.00e+00, 1.29e+01, 5.00e+00, 3.90e+00],
  16. [1.81e+01, 0.00e+00, 0.00e+00, 1.89e+01, 5.00e+00, 3.90e+00]]
  17. Obstacles = []
  18. for i in block:
  19. i = np.array(i)
  20. Obstacles.append([j for j in i])
  21. return np.array(Obstacles)
  22. def getAABB(blocks):
  23. # used for Pyrr package for detecting collision
  24. AABB = []
  25. for i in blocks:
  26. AABB.append(np.array([np.add(i[0:3], -0), np.add(i[3:6], 0)])) # make AABBs alittle bit of larger
  27. return AABB
  28. def getballs():
  29. spheres = [[16,2.5,4,2],[10,2.5,1,1]]
  30. Obstacles = []
  31. for i in spheres:
  32. Obstacles.append([j for j in i])
  33. return np.array(Obstacles)
  34. def add_block(block = [1.51e+01, 0.00e+00, 2.10e+00, 1.59e+01, 5.00e+00, 6.00e+00]):
  35. return block
  36. class env():
  37. def __init__(self, xmin=0, ymin=0, zmin=0, xmax=20, ymax=5, zmax=6, resolution=1):
  38. self.resolution = resolution
  39. self.boundary = np.array([xmin, ymin, zmin, xmax, ymax, zmax])
  40. self.blocks = getblocks()
  41. self.AABB = getAABB(self.blocks)
  42. self.balls = getballs()
  43. self.start = np.array([0.5, 2.5, 5.5])
  44. self.goal = np.array([19.0, 2.5, 5.5])
  45. def change(self):
  46. newblock = add_block()
  47. self.blocks = np.vstack([self.blocks,newblock])
  48. self.AABB = getAABB(self.blocks)
  49. if __name__ == '__main__':
  50. newenv = env()
  51. print(newenv.balls)