Agent2d.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Agent2d.h
  3. * RVO2 Library
  4. *
  5. * Copyright 2008 University of North Carolina at Chapel Hill
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * Please send all bug reports to <geom@cs.unc.edu>.
  20. *
  21. * The authors may be contacted via:
  22. *
  23. * Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha
  24. * Dept. of Computer Science
  25. * 201 S. Columbia St.
  26. * Frederick P. Brooks, Jr. Computer Science Bldg.
  27. * Chapel Hill, N.C. 27599-3175
  28. * United States of America
  29. *
  30. * <http://gamma.cs.unc.edu/RVO2/>
  31. */
  32. #ifndef RVO2D_AGENT_H_
  33. #define RVO2D_AGENT_H_
  34. /**
  35. * \file Agent2d.h
  36. * \brief Contains the Agent class.
  37. */
  38. #include "Definitions.h"
  39. #include "RVOSimulator2d.h"
  40. namespace RVO2D {
  41. /**
  42. * \brief Defines an agent in the simulation.
  43. */
  44. class Agent2D {
  45. public:
  46. /**
  47. * \brief Constructs an agent instance.
  48. * \param sim The simulator instance.
  49. */
  50. explicit Agent2D();
  51. /**
  52. * \brief Computes the neighbors of this agent.
  53. */
  54. void computeNeighbors(RVOSimulator2D *sim_);
  55. /**
  56. * \brief Computes the new velocity of this agent.
  57. */
  58. void computeNewVelocity(RVOSimulator2D *sim_);
  59. /**
  60. * \brief Inserts an agent neighbor into the set of neighbors of
  61. * this agent.
  62. * \param agent A pointer to the agent to be inserted.
  63. * \param rangeSq The squared range around this agent.
  64. */
  65. void insertAgentNeighbor(const Agent2D *agent, float &rangeSq);
  66. /**
  67. * \brief Inserts a static obstacle neighbor into the set of neighbors
  68. * of this agent.
  69. * \param obstacle The number of the static obstacle to be
  70. * inserted.
  71. * \param rangeSq The squared range around this agent.
  72. */
  73. void insertObstacleNeighbor(const Obstacle2D *obstacle, float rangeSq);
  74. /**
  75. * \brief Updates the two-dimensional position and two-dimensional
  76. * velocity of this agent.
  77. */
  78. void update(RVOSimulator2D *sim_);
  79. std::vector<std::pair<float, const Agent2D *> > agentNeighbors_;
  80. size_t maxNeighbors_;
  81. float maxSpeed_;
  82. float neighborDist_;
  83. Vector2 newVelocity_;
  84. std::vector<std::pair<float, const Obstacle2D *> > obstacleNeighbors_;
  85. std::vector<Line> orcaLines_;
  86. Vector2 position_;
  87. Vector2 prefVelocity_;
  88. float radius_;
  89. float timeHorizon_;
  90. float timeHorizonObst_;
  91. Vector2 velocity_;
  92. float height_ = 0.0;
  93. float elevation_ = 0.0;
  94. uint32_t avoidance_layers_ = 1;
  95. uint32_t avoidance_mask_ = 1;
  96. float avoidance_priority_ = 1.0;
  97. size_t id_;
  98. friend class KdTree2D;
  99. friend class RVOSimulator2D;
  100. };
  101. /**
  102. * \relates Agent
  103. * \brief Solves a one-dimensional linear program on a specified line
  104. * subject to linear constraints defined by lines and a circular
  105. * constraint.
  106. * \param lines Lines defining the linear constraints.
  107. * \param lineNo The specified line constraint.
  108. * \param radius The radius of the circular constraint.
  109. * \param optVelocity The optimization velocity.
  110. * \param directionOpt True if the direction should be optimized.
  111. * \param result A reference to the result of the linear program.
  112. * \return True if successful.
  113. */
  114. bool linearProgram1(const std::vector<Line> &lines, size_t lineNo,
  115. float radius, const Vector2 &optVelocity,
  116. bool directionOpt, Vector2 &result);
  117. /**
  118. * \relates Agent
  119. * \brief Solves a two-dimensional linear program subject to linear
  120. * constraints defined by lines and a circular constraint.
  121. * \param lines Lines defining the linear constraints.
  122. * \param radius The radius of the circular constraint.
  123. * \param optVelocity The optimization velocity.
  124. * \param directionOpt True if the direction should be optimized.
  125. * \param result A reference to the result of the linear program.
  126. * \return The number of the line it fails on, and the number of lines if successful.
  127. */
  128. size_t linearProgram2(const std::vector<Line> &lines, float radius,
  129. const Vector2 &optVelocity, bool directionOpt,
  130. Vector2 &result);
  131. /**
  132. * \relates Agent
  133. * \brief Solves a two-dimensional linear program subject to linear
  134. * constraints defined by lines and a circular constraint.
  135. * \param lines Lines defining the linear constraints.
  136. * \param numObstLines Count of obstacle lines.
  137. * \param beginLine The line on which the 2-d linear program failed.
  138. * \param radius The radius of the circular constraint.
  139. * \param result A reference to the result of the linear program.
  140. */
  141. void linearProgram3(const std::vector<Line> &lines, size_t numObstLines, size_t beginLine,
  142. float radius, Vector2 &result);
  143. }
  144. #endif /* RVO2D_AGENT_H_ */