44
55def collision_routine (E1 , E2 ):
66 """
7- Calls the method :meth:'collide_detect' to determine whether the given two ellipsoid objects overlap using
8- the Algebraic separation condition developed by W. Wang et al. A detailed description is provided
9- therein.
10-
11- Also calls the :meth:`collision_react` to evaluate the response after collision.
12-
13- :param E1: Ellipsoid :math:`i`
14- :type E1: object :obj:`Ellipsoid`
15- :param E2: Ellipsoid :math:`j`
16- :type E2: object :obj:`Ellipsoid`
17-
18- .. note:: 1. If both the particles to be tested for overlap are spheres, then the bounding sphere hierarchy is
19- sufficient to determine whether they overlap.
20- 2. Else, if either of them is an ellipsoid, then their coefficients, positions & rotation matrices are
21- used to determine whether they overlap.
7+ Detect and handle collision between two ellipsoid objects
8+
9+ Uses the algebraic separation condition by W. Wang et al. to detect overlap
10+ between two ellipsoids, and if a collision occurs, computes the contact
11+ response via the `collision_react` method.
12+
13+ Parameters
14+ ----------
15+ E1 : Ellipsoid
16+ First ellipsoid object (particle i)
17+ E2 : Ellipsoid
18+ Second ellipsoid object (particle j)
19+
20+ Returns
21+ -------
22+ bool
23+ True if overlap (collision) is detected, False otherwise
24+
25+ Notes
26+ -----
27+ - If both particles are spheres, the bounding sphere hierarchy alone
28+ suffices to detect collision.
29+ - If either particle is an ellipsoid, their coefficients, positions,
30+ and rotation matrices are used in the overlap test.
2231 """
2332
2433 # call the collision detection algorithm
@@ -31,44 +40,45 @@ def collision_routine(E1, E2):
3140
3241
3342def collision_react (ell1 , ell2 ):
34- r"""
35- Evaluates and modifies the magnitude and direction of the ellipsoid's velocity after collision.
36-
37- :param ell1: Ellipsoid :math:`i`
38- :type ell1: object :obj:`Ellipsoid`
39- :param ell2: Ellipsoid :math:`j`
40- :type ell2: object :obj:`Ellipsoid`
41-
42- .. note:: Consider two ellipsoids :math:`i, j` at collision. Let them occupy certain positions in space
43- defined by the position vectors :math:`\mathbf{r}^{i}, \mathbf{r}^{j}` and have certain
44- velocities represented by :math:`\mathbf{v}^{i}, \mathbf{v}^{j}` respectively. The objective
45- is to find the velocity vectors after collision. The elevation angle :math:`\phi` between
46- the ellipsoids is determined by,
47-
48- .. image:: /figs/elevation_ell.png
49- :width: 200px
50- :height: 45px
51- :align: center
52-
53- where :math:`dx, dy, dz` are defined as the distance between the two ellipsoid centers along
54- :math:`x, y, z` directions given by,
55-
56- .. image:: /figs/dist_ell.png
57- :width: 110px
58- :height: 75px
59- :align: center
60-
61- Depending on the magnitudes of :math:`dx, dz` as projected on the :math:`x-z` plane, the angle
62- :math:`\Theta` is computed.
63- The angles :math:`\Theta` and :math:`\phi` determine the in-plane and out-of-plane directions along which
64- the ellipsoid :math:`i` would bounce back after collision. Thus, the updated velocity vector components
65- along the :math:`x, y, z` directions are determined by,
66-
67- .. image:: /figs/velocities_ell.png
68- :width: 180px
69- :height: 80px
70- :align: center
71-
43+ """
44+ Evaluates and modifies the magnitude and direction of the ellipsoid's velocity after collision
45+
46+ Parameters
47+ ----------
48+ ell1 : Ellipsoid
49+ Ellipsoid i
50+ ell2 : Ellipsoid
51+ Ellipsoid j
52+
53+ Notes
54+ -----
55+ Consider two ellipsoids i, j at collision. Let them occupy certain positions in space
56+ defined by the position vectors r^i, r^j and have certain velocities represented by v^i, v^j
57+ respectively. The objective is to find the velocity vectors after collision. The elevation angle φ
58+ between the ellipsoids is determined by:
59+
60+ .. image:: /figs/elevation_ell.png
61+ :width: 200px
62+ :height: 45px
63+ :align: center
64+
65+ where dx, dy, dz are defined as the distance between the two ellipsoid centers along
66+ x, y, z directions given by:
67+
68+ .. image:: /figs/dist_ell.png
69+ :width: 110px
70+ :height: 75px
71+ :align: center
72+
73+ Depending on the magnitudes of dx, dz as projected on the x-z plane, the angle Θ is computed.
74+ The angles Θ and φ determine the in-plane and out-of-plane directions along which
75+ ellipsoid i would bounce back after collision. Thus, the updated velocity vector components
76+ along the x, y, z directions are determined by:
77+
78+ .. image:: /figs/velocities_ell.png
79+ :width: 180px
80+ :height: 80px
81+ :align: center
7282 """
7383 cdir = ell1 .get_pos () - ell2 .get_pos ()
7484 dst = np .linalg .norm (cdir )
@@ -87,24 +97,37 @@ def collision_react(ell1, ell2):
8797
8898
8999def collide_detect (coef_i , coef_j , r_i , r_j , A_i , A_j ):
90- r"""Implementation of Algebraic separation condition developed by
91- W. Wang et al. 2001 for overlap detection between two static ellipsoids.
92- Kudos to ChatGPT for support with translation from C++ code.
93-
94- :param coef_i: Coefficients of ellipsoid :math:`i`
95- :type coef_i: numpy array
96- :param coef_j: Coefficients of ellipsoid :math:`j`
97- :type coef_j: numpy array
98- :param r_i: Position of ellipsoid :math:`i`
99- :type r_i: numpy array
100- :param r_j: Position of ellipsoid :math:`j`
101- :type r_j: numpy array
102- :param A_i: Rotation matrix of ellipsoid :math:`i`
103- :type A_i: numpy array
104- :param A_j: Rotation matrix of ellipsoid :math:`j`
105- :type A_j: numpy array
106- :returns: **True** if ellipsoids :math:`i, j` overlap, else **False**
107- :rtype: boolean
100+ """
101+ Determines overlap between two static ellipsoids using the Algebraic Separation Condition
102+ developed by W. Wang et al., 2001. This function implements the method for two ellipsoids
103+ with given coefficients, positions, and rotation matrices
104+
105+ Parameters
106+ ----------
107+ coef_i : numpy array
108+ Coefficients of ellipsoid i
109+ coef_j : numpy array
110+ Coefficients of ellipsoid j
111+ r_i : numpy array
112+ Position vector of ellipsoid i
113+ r_j : numpy array
114+ Position vector of ellipsoid j
115+ A_i : numpy array
116+ Rotation matrix of ellipsoid i
117+ A_j : numpy array
118+ Rotation matrix of ellipsoid j
119+
120+ Returns
121+ -------
122+ bool
123+ True if ellipsoids i and j overlap, False otherwise
124+
125+ Notes
126+ -----
127+ The method calculates the characteristic polynomial based on the ellipsoid coefficients
128+ and rigid body transformations. Roots of this polynomial are used with the Algebraic
129+ Separation Condition to determine whether the ellipsoids intersect. Real roots with
130+ negative values are analyzed to establish the overlap.
108131 """
109132 SMALL = 1.e-12
110133
0 commit comments