# ars

committed ec40911

# ars/model/physics/base.py

 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
+
+	def calc_potential_energy(self, gravity):
+		r"""Calculate the potential energy of the body due to its position
+		(x) and the gravitational acceleration (g).
+
+		.. math::
+			E_p &= m \cdot g \cdot h = - m \cdot g^\top x
+
+		:param gravity: gravitational acceleration vector
+		:type gravity: tuple of 3 floats
+		:return: potential energy
+		:rtype: float
+
+		"""
+		mass = self.get_mass()
+		return -mass * mut.dot_product(gravity, self.get_position())
+
 #===============================================================================
 # GETTERS AND SETTERS
 #===============================================================================
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.