spheroid.py
Go to the documentation of this file.
1 # Copyright (c) 2016 The UUV Simulator Authors.
2 # All rights reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 from plume import Plume
16 import numpy as np
17 from tf.transformations import quaternion_matrix
18 
19 
20 class PlumeSpheroid(Plume):
21  """Plume model to generate a static plume with spheroid form.
22  """
23  LABEL = 'spheroid'
24 
25  def __init__(self, a, c, orientation, source_pos, n_points, start_time):
26  """Spheroid plume class constructor.
27 
28  > **Parameters**
29 
30  * `a` and `c` (*type:* `float`): length of the ellipsoid's principal
31  semi-axes
32  * `orientation` (*type:* `list`): quaternion describing the orientation
33  of the ellipsoid
34  * `n_points` (*type:* `int`): maximum number of plume particles
35  * `start_time` (*type:* `float`): time stamp for the creation of
36  the plume model
37  """
38  Plume.__init__(self, source_pos, n_points, start_time)
39 
40  assert a > 0 and c > 0, 'The length of the principal axes must be ' \
41  'greater than zero'
42  assert orientation.size == 4, 'Orientation vector must be a quaternion'
43  # Set the length of the principal axes
44  self._a = a
45  self._c = c
46 
47  # Store the orientation
48  self._rot = orientation
49 
50  def update(self, t=0.0):
51  """Update the position of all particles and create/remove particles from
52  the plume according to the bounding box limit constraints and the
53  maximum number of particles allowed.
54 
55  > **Parameters**
56 
57  * `t` (*type: `float`): current time stamp in seconds
58 
59  > **Returns**
60 
61  `True` if update was succesful, `False` if computed time step is invalid.
62  """
63  if self._pnts is not None:
64  return True
65 
66  self._t = t
67  theta_range = np.linspace(-np.pi / 2, np.pi / 2, self._n_points)
68  phi_range = np.linspace(-np.pi, np.pi, self._n_points)
69 
70  theta, phi = np.meshgrid(theta_range, phi_range)
71  # Generate the point cloud for the spheroid
72  self._pnts = np.vstack(
73  (self._a * np.multiply(np.cos(theta.flatten()),
74  np.cos(phi.flatten())),
75  self._a * np.multiply(np.cos(theta.flatten()),
76  np.sin(phi.flatten())),
77  self._c * np.sin(theta.flatten()))).T
78 
79  self._time_creation = t * np.ones(self._pnts.shape[0])
80 
81  self._pnts = None
82  # Change the point cloud's orientation
83  # Calculate the rotation matrix first
84  rot_matrix = quaternion_matrix(self._rot)[0:3, 0:3]
85  for t, p in zip(theta.flatten(), phi.flatten()):
86  vec = [self._a * np.cos(t) * np.cos(p),
87  self._a * np.cos(t) * np.sin(p),
88  self._c * np.sin(t)]
89  vec = np.dot(rot_matrix, vec)
90  if self._pnts is None:
91  self._pnts = np.array(vec)
92  else:
93  self._pnts = np.vstack((self._pnts, vec))
94 
95  # Translate the point cloud to the correct position
96  for i in range(len(self._source_pos)):
97  self._pnts[:, i] += self._source_pos[i]
98 
99  self.apply_constraints()
100  return True
def __init__(self, a, c, orientation, source_pos, n_points, start_time)
Definition: spheroid.py:25


uuv_plume_simulator
Author(s): Musa Morena Marcusso Manhaes
autogenerated on Mon Jun 10 2019 15:41:28