Example #1
0
    def Add(self,VectorType,Vector,DVector=None):
        """Add a Vector to the object.
        
        ...

        Attributes
        ----------
        VectorType: str
            Type of the adding Vector. 'force' or 'velocity'. 
        Vector: Vector
            A vector which will be added to the object
        DVector: Vector
            A vector which is the position vector of added force. (Default None)
        """
        if str(VectorType) == "force":
            self.Forces=np.append(self.Forces,Vector)
            self.ForceDistances=np.append(self.ForceDistances,DVector)
            self.Torques=np.append(self.Torques,veop.CrossProduct(DVector,Vector))
        elif str(VectorType) == "velocity":
            self.Velocity = Vector
        
        self.NetForce = veop.VectorAddition(self.NetForce,self.Forces[-1])
        self.Acceleration = veop.List2Vector(self.NetForce.numpy_array/self.Mass)
        self.NetTorque = veop.MultiVectorAddition(self.Torques)
        self.AngularVelocity = veop.List2Vector(self.Radius * self.Velocity.numpy_array)
        self.Momentum = veop.List2Vector(self.Mass * self.Velocity.numpy_array)
        self.LinearKineticEnergy = 0.5 * self.Mass * self.Velocity.magnitude
        self.AngularKineticEnergy = 0.5 * self.MomentOfInertia * self.AngularVelocity.magnitude
Example #2
0
    def Future(self,Type,Time):
        """Calculate future attributes

        This function calculate future velocity or position of the object at a specific time.

        Attributes
        ----------
        Type: str
            'velocity' or 'position'
        Time: int
            Time that the function calculate velocity or position of the object, in second.
        """
        if str(Type) == "velocity":
            return veop.List2Vector(self.Velocity.numpy_array + self.Acceleration.numpy_array*Time)
        elif str(Type) == "position":
            return veop.List2Vector(self.Position.numpy_array + self.Velocity.numpy_array*Time + 0.5 * self.Acceleration.numpy_array * Time* Time)
Example #3
0
    def Elastic(self):
        """Calculate final velocities of two object after an elastic collision 
        
        Returns Vector,Vector

        Attributes
        ----------
        Object1: Object
            First object of an elactic collision
        Object2: Object
            Second object of an elastic collision
        """
        RlV = veop.List2Vector(veop.RelativeVector(self.Object2.Velocity,self.Object1.Velocity).numpy_array)
        IMom = veop.List2Vector(self.Object1.Momentum.numpy_array+self.Object2.Momentum.numpy_array)
        
        O2fV = veop.List2Vector(IMom.numpy_array+RlV.numpy_array*self.Object1.Mass/(self.Object1.Mass+self.Object2.Mass))
        O1fV = veop.List2Vector(O2fV.numpy_array-RlV.numpy_array)
        return O1fV,O2fV
Example #4
0
 def __init__(self,Space,Mass,MomentOfInertia,Position):
     self.Space = Space 
     self.Mass = Mass
     self.MomentOfInertia = MomentOfInertia
     self.Position = Position
     self.Radius = math.sqrt(self.MomentOfInertia / self.Mass)
     self.Forces = np.array([veop.List2Vector(self.Mass * self.Space.Gravity.numpy_array)])
     self.ForceDistances = []
     self.Torques = [veop.Vector(0,0,0)]
     self.Velocity = veop.Vector(0,0,0)
     self.AngularVelocity = veop.List2Vector(self.Radius * self.Velocity.numpy_array)
     self.Momentum = veop.List2Vector(self.Mass * self.Velocity.numpy_array)
     self.LinearKineticEnergy = 0.5 * self.Mass * self.Velocity.magnitude ** 2 
     self.AngularKineticEnergy = 0.5 * self.MomentOfInertia * self.AngularVelocity.magnitude
     self.GravityPotentialEnergy = self.Mass * veop.DotProduct(self.Space.Gravity,self.Position)
     self.NetForce = self.Space.Gravity
     self.NetTorque = veop.Vector(0,0,0)
     self.Acceleration = veop.List2Vector(self.NetForce.numpy_array/self.Mass)
Example #5
0
def EField(charge,point):
    """Calculate electric field caused by a charge at a point
    
    Returns Vector

    charge: Charge
        Charge that cause electric field
    point: Vector
        Point in a 3-D space to calculate electric field
    """
    E = cn.k.Value * charge.charge / veop.RelativeVector(charge.position,point).magnitude**2
    vector = veop.List2Vector(E*veop.RelativeVector(point,charge.position).unitVector().numpy_array)
    return vector
Example #6
0
def DistanceB2Object(FirstObject,SecondObject):
    """Calculate distance between two objects.

    Position of second object - position of first object. Returns Vector.

    Attributes
    ----------
    FirstObject: Object
        First object
    SecondObject: Object
        Second object
    """
    return veop.List2Vector(SecondObject.Position.numpy_array-FirstObject.Position.numpy_array)   
Example #7
0
def DipoleMoment(NegativeCharge,PositiveCharge):
    """Calculate the dipole moment of two charges

    Returns Vector

    Attribute
    ---------
    NegativeCharge: Charge
        Negative charge
    PositiveCharge: Charge
        Positive charge
    """
    return veop.List2Vector(PositiveCharge.charge * veop.RelativeVector(PositiveCharge.position,NegativeCharge.position).numpy_array)
Example #8
0
def CoulombsLaw(charge1,charge2):
    """Calculate electric force act on second charge applied by first charge 
    
    Returns Vector

    Attributes
    ----------
    charge1: Charge
        First charge
    charge2: Charge
        Second Charge
    """
    F = cn.k.Value * charge1.charge * charge2.charge / veop.RelativeVector(charge1.position,charge2.position).magnitude**2
    vector = veop.List2Vector(F * veop.RelativeVector(charge2.position,charge1.position).unitVector().numpy_array)
    return vector
Example #9
0
def GravitationalForce(FirstObject,SecondObject):
    """Calculate the gravitational force act on second object applied by first object

    Returns Vector

    Attributes
    ----------
    FirstObject: Object
        First object
    SecondObject: Object
        Second object
    """
    gF = cn.G.Value * FirstObject.Mass * SecondObject.Mass / (DistanceB2Object(FirstObject,SecondObject).magnitude)**2

    vector = veop.List2Vector(gF * DistanceB2Object(SecondObject,FirstObject).unitVector().numpy_array)

    return vector