Skip to content

Commit

Permalink
Preparation for Zenodo commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mariomerinomartinez committed Jan 7, 2019
1 parent 84bb3ad commit 6614067
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion +anakin/basis.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ purely numeric matrix (symbolic variables must be used)
end
end
end
methods % overloads
methods (Hidden = true) % overloads
function value = eq(B1,B2) % overload ==
if isa(B1.m,'sym') || isa(B1.m,'sym') % symbolic inputs
value = isAlways(B1.m==B2.m,'Unknown','false'); % In case of doubt, false
Expand Down
55 changes: 32 additions & 23 deletions +anakin/particle.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
DESCRIPTION:
particle: class to model a point particle. Inherits from point.
particle: class to model a point particle.
SYNTAX:
P0 = anakin.particle(); % returns default object
Expand Down Expand Up @@ -33,10 +33,13 @@
AUTHOR:
Mario Merino <mario.merino@uc3m.es>
%}
classdef particle < anakin.point
classdef particle
properties
mass anakin.tensor = anakin.tensor(1); % mass of the object
forces cell = {}; % cell array with all forces acting on the particle
point anakin.point = anakin.point; % point where the object is
end
properties % extensions
forces cell = {}; % cell array with all forces (vectors) acting on the object
end
methods % creation
function P = particle(varargin) % constructor
Expand All @@ -45,23 +48,23 @@
return;
case 1
Pt = anakin.particle(varargin{1},anakin.frame);
P.pos0 = Pt.pos0;
P.mass = Pt.mass;
P.point = Pt.point;
case 2
if isa(varargin{end},'anakin.frame') % last is frame
if isa(varargin{1},'anakin.point') || isa(varargin{1},'anakin.tensor') || numel(varargin{1}) == 3 % (vector or components), frame
P.pos0 = anakin.tensor(varargin{2}.basis.matrix * anakin.tensor(varargin{1}).components + varargin{2}.origin.coordinates);
else % mass, frame
P.pos0 = varargin{2}.origin;
P.point = anakin.point(varargin{2}.basis.matrix * anakin.tensor(varargin{1}).components + varargin{2}.origin.coordinates);
else % mass, frame
P.mass = anakin.tensor(varargin{1});
P.point = varargin{2}.origin;
end
else
Pt = anakin.particle(varargin{1},varargin{2},anakin.frame);
P.pos0 = Pt.pos0;
P.mass = Pt.mass;
P.point = Pt.point;
end
case 3
P.pos0 = anakin.tensor(varargin{3}.basis.matrix * anakin.tensor(varargin{2}).components + varargin{3}.origin.coordinates);
P.point = anakin.point(varargin{3}.basis.matrix * anakin.tensor(varargin{2}).components + varargin{3}.origin.coordinates);
P.mass = anakin.tensor(varargin{1});
otherwise % other possibilities are not allowed
error('Wrong number of arguments in particle');
Expand All @@ -88,42 +91,48 @@
P.forces = value;
end
end
methods(Hidden = true) % overloads
methods (Hidden = true) % overloads
function value = eq(P1,P2) % overload ==
value = (P1.point == P2.point) && (P1.mass == P2.mass);
end
function value = ne(P1,P2) % overload =~
value = ~eq(P1,P2);
end
function disp(P) % display
disp('Particle with mass:')
disp(P.mass.components)
disp('And canonical position vector components:')
disp(P.pos.components)
disp('And canonical coordinates:')
disp(P.point.coordinates)
end
end
methods % functionality
methods % general functionality
function p = p(P,S1) % linear momentum in S1
if exist('S1','var')
p = P.mass*P.vel(S1);
p = P.mass*P.point.vel(S1);
else
p = P.mass*P.vel;
p = P.mass*P.point.vel;
end
end
function H = H(P,O,S1) % angular momentum about O in S1
if ~exist('O','var')
O = anakin.point; % default point
end
if exist('S1','var')
H = cross(P.pos0-O.pos0, P.p(S1));
H = cross(P.point.pos0-O.pos0, P.p(S1));
else
H = cross(P.pos0-O.pos0, P.p);
H = cross(P.point.pos0-O.pos0, P.p);
end
end
function T = T(P,S1) % kinetic energy in S1
if exist('S1','var')
vel = P.vel(S1).components;
vel = P.point.vel(S1).components;
else
vel = P.vel.components;
vel = P.point.vel.components;
end
T = (P.mass/2) * dot(vel,vel);
end
function eqs = equations(P,B1) % returns vector of equations of motion projected in basis B1
MA = P.mass*P.accel;
MA = P.mass*P.point.accel;
F = anakin.tensor([0;0;0]); % allocate;
for i=1:length(P.forces)
F = F + P.forces{i};
Expand All @@ -142,15 +151,15 @@ function disp(P) % display
end
function inertia = inertia(P,O) % inertia tensor of the particle with respect to point O
if exist('O','var')
r = P.pos0 - O;
r = P.point.coordinates - O.coordiantes;
else
r = P.pos0;
r = P.point.coordinates;
end
inertia = P.mass * (norm(r)^2 * anakin.tensor(eye(3)) - product(r,r));
end
function P_ = subs(P,variables,values) % particularize symbolic vector
P_ = P;
P_.pos0 = P.pos0.subs(variables,values);
P_.point = P.point.subs(variables,values);
P_.mass = P.mass.subs(variables,values);
end
end
Expand Down
30 changes: 15 additions & 15 deletions +anakin/point.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ of the point with respect to another reference frame (symbolic variables
end
end
end
methods % overloads
methods (Hidden = true) % overloads
function value = eq(A1,A2) % overload ==
value = (A1.pos0 == A2.pos0);
end
function value = ne(A1,A2)
function value = ne(A1,A2) % overload =~
value = ~eq(A1,A2);
end
function disp(A) % display
Expand Down Expand Up @@ -78,29 +78,29 @@ function disp(A) % display
A_ = A;
A_.pos0 = A.pos0 + a;
end
function rO_1 = pos(A,S1) % Returns the position vector of the point with respect to reference frame S1
function r = pos(A,S1) % Returns the position vector of the point with respect to reference frame S1
if exist('S1','var') % If no S1 is given, assume the canonical reference frame
rO_1 = A.pos0 - S1.origin;
r = A.pos0 - S1.origin;
else
rO_1 = A.pos0;
r = A.pos0;
end
end
function vO_1 = vel(A,S1) % Returns the velocity vector of the point with respect to reference frame S1
function v = vel(A,S1) % Returns the velocity vector of the point with respect to reference frame S1
if exist('S1','var') % If no S1 is given, assume the canonical reference frame
rO_1 = A.pos(S1);
vO_1 = rO_1.dt(S1.basis);
r = A.pos(S1);
v = r.dt(S1.basis);
else
rO_1 = A.pos;
vO_1 = rO_1.dt;
r = A.pos;
v = r.dt;
end
end
function aO_1 = accel(A,S1) % Returns the acceleration vector of the point with respect to reference frame S1
function a = accel(A,S1) % Returns the acceleration vector of the point with respect to reference frame S1
if exist('S1','var') % If no S1 is given, assume the canonical reference frame
vO_1 = A.vel(S1);
aO_1 = vO_1.dt(S1.basis);
v = A.vel(S1);
a = v.dt(S1.basis);
else
vO_1 = A.vel;
aO_1 = vO_1.dt;
v = A.vel;
a = v.dt;
end
end
function A_ = subs(A,variables,values) % Particularize symbolic frame
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ Currently Anakin defines the following classes:
* `basis`: vector bases
* `frame`: reference frames
* `point`: geometric points
* `particle`: point particles
* `body`: rigid bodies
* `particle`: point particles

The description of the properties and methods of each class is included in the
header comments of each code file.
Expand Down
File renamed without changes.
Binary file removed problems/figs/solved_motion.avi
Binary file not shown.
Binary file modified problems/two_particles_on_cone_with_string.mlx
Binary file not shown.

0 comments on commit 6614067

Please sign in to comment.