Commits

German Larrain committed d03b7e7

physics.base.Body: added method 'calc_potential_energy'.

  • Participants
  • Parent commits d93a795
  • Branches dev-sensors

Comments (0)

Files changed (1)

File ars/model/physics/base.py

 		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
 #===============================================================================