# Commits

committed 2d52072

physics.base.Body: added methods 'calc_translation_kinetic_energy' and 'calc_rotation_kinetic_energy'.

• Participants
• Parent commits aafcbf5
• Branches dev-sensors

# File ars/model/physics/base.py

• Ignore whitespace
 from abc import ABCMeta, abstractmethod, abstractproperty

 import ars.exceptions as exc
+import ars.utils.mathematical as mut


 class Engine:
 		geom.attach_body(self)
 		self._attached_geom = geom

+	#==========================================================================
+	# Calculations
+	#==========================================================================
+
+	def calc_translation_kinetic_energy(self):
+		r"""Calculate the kinetic energy of the body due to translational
+		movement.
+
+		.. math::
+			E_{kt} = \frac{1}{2} m v^2
+			  = \frac{1}{2} m \cdot v^\top v
+
+		:return: kinetic energy
+		:rtype: float
+
+		"""
+		mass = self.get_mass()
+		linear_vel = self.get_linear_velocity()
+		return mass * mut.dot_product(linear_vel, linear_vel) / 2.0
+
+	def calc_rotation_kinetic_energy(self):
+		r"""Calculate the kinetic energy of the body due to rotational
+		movement.
+
+		.. math::
+			E_{kr} = \frac{1}{2} I \omega^2 =
+			  \frac{1}{2} \omega^\top \mathbf{I} \omega
+
+		:return: kinetic energy
+		:rtype: float
+
+		"""
+		It = self.get_inertia_tensor()
+		angular_vel = self.get_angular_velocity()
+		return mut.vector_matrix_vector(angular_vel, It) / 2.0
+
 #===============================================================================
 # GETTERS AND SETTERS
 #===============================================================================