env3D.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. class aabb(object):
  29. def __init__(self,AABB):
  30. self.P = [(AABB[3] + AABB[0])/2, (AABB[4] + AABB[1])/2, (AABB[5] + AABB[2])/2]# center point
  31. self.E = [(AABB[3] - AABB[0])/2, (AABB[4] - AABB[1])/2, (AABB[5] - AABB[2])/2]# extents
  32. def getAABB2(blocks):
  33. # used in lineAABB
  34. AABB = []
  35. for i in blocks:
  36. AABB.append(aabb(i))
  37. return AABB
  38. def getballs():
  39. spheres = [[16,2.5,4,2],[10,2.5,1,1]]
  40. Obstacles = []
  41. for i in spheres:
  42. Obstacles.append([j for j in i])
  43. return np.array(Obstacles)
  44. def add_block(block = [1.51e+01, 0.00e+00, 2.10e+00, 1.59e+01, 5.00e+00, 6.00e+00]):
  45. return block
  46. class env():
  47. def __init__(self, xmin=0, ymin=0, zmin=0, xmax=20, ymax=5, zmax=6, resolution=1):
  48. self.resolution = resolution
  49. self.boundary = np.array([xmin, ymin, zmin, xmax, ymax, zmax])
  50. self.blocks = getblocks()
  51. self.AABB = getAABB2(self.blocks)
  52. self.balls = getballs()
  53. self.start = np.array([0.5, 2.5, 5.5])
  54. self.goal = np.array([19.0, 2.5, 5.5])
  55. def change(self):
  56. newblock = add_block()
  57. self.blocks = np.vstack([self.blocks,newblock])
  58. self.AABB = getAABB(self.blocks)
  59. if __name__ == '__main__':
  60. newenv = env()
  61. print(newenv.balls)