1
1
%{
2
2
DESCRIPTION:
3
- particle: class to model a point particle. Inherits from point.
3
+ particle: class to model a point particle.
4
4
5
5
SYNTAX:
6
6
P0 = anakin.particle(); % returns default object
33
33
AUTHOR:
34
34
35
35
%}
36
- classdef particle < anakin . point
36
+ classdef particle
37
37
properties
38
38
mass anakin.tensor = anakin.tensor(1 ); % mass of the object
39
- forces cell = {}; % cell array with all forces acting on the particle
39
+ point anakin.point = anakin.point; % point where the object is
40
+ end
41
+ properties % extensions
42
+ forces cell = {}; % cell array with all forces (vectors) acting on the object
40
43
end
41
44
methods % creation
42
45
function P = particle(varargin ) % constructor
45
48
return ;
46
49
case 1
47
50
Pt = anakin .particle(varargin{1 },anakin .frame );
48
- P.pos0 = Pt .pos0 ;
49
51
P.mass = Pt .mass ;
52
+ P.point = Pt .point ;
50
53
case 2
51
54
if isa(varargin{end },' anakin.frame' ) % last is frame
52
55
if isa(varargin{1 },' anakin.point' ) || isa(varargin{1 },' anakin.tensor' ) || numel(varargin{1 }) == 3 % (vector or components), frame
53
- P.pos0 = anakin .tensor(varargin{2 }.basis.matrix * anakin .tensor(varargin{1 }).components + varargin{2 }.origin.coordinates);
54
- else % mass, frame
55
- P.pos0 = varargin{2 }.origin;
56
+ P.point = anakin .point(varargin{2 }.basis.matrix * anakin .tensor(varargin{1 }).components + varargin{2 }.origin.coordinates);
57
+ else % mass, frame
56
58
P.mass = anakin .tensor(varargin{1 });
59
+ P.point = varargin{2 }.origin;
57
60
end
58
61
else
59
62
Pt = anakin .particle(varargin{1 },varargin{2 },anakin .frame );
60
- P.pos0 = Pt .pos0 ;
61
63
P.mass = Pt .mass ;
64
+ P.point = Pt .point ;
62
65
end
63
66
case 3
64
- P.pos0 = anakin .tensor (varargin{3 }.basis.matrix * anakin .tensor(varargin{2 }).components + varargin{3 }.origin.coordinates);
67
+ P.point = anakin .point (varargin{3 }.basis.matrix * anakin .tensor(varargin{2 }).components + varargin{3 }.origin.coordinates);
65
68
P.mass = anakin .tensor(varargin{1 });
66
69
otherwise % other possibilities are not allowed
67
70
error(' Wrong number of arguments in particle' );
88
91
P.forces = value ;
89
92
end
90
93
end
91
- methods (Hidden = true ) % overloads
94
+ methods (Hidden = true ) % overloads
95
+ function value = eq(P1 ,P2 ) % overload ==
96
+ value = (P1 .point == P2 .point ) && (P1 .mass == P2 .mass );
97
+ end
98
+ function value = ne(P1 ,P2 ) % overload =~
99
+ value = ~eq(P1 ,P2 );
100
+ end
92
101
function disp(P ) % display
93
102
disp(' Particle with mass:' )
94
103
disp(P .mass .components )
95
- disp(' And canonical position vector components :' )
96
- disp(P .pos . components )
104
+ disp(' And canonical coordinates :' )
105
+ disp(P .point . coordinates )
97
106
end
98
107
end
99
- methods % functionality
108
+ methods % general functionality
100
109
function p = p(P ,S1 ) % linear momentum in S1
101
110
if exist(' S1' ,' var' )
102
- p = P .mass * P .vel(S1 );
111
+ p = P .mass * P .point . vel(S1 );
103
112
else
104
- p = P .mass * P .vel ;
113
+ p = P .mass * P .point . vel ;
105
114
end
106
115
end
107
116
function H = H(P ,O ,S1 ) % angular momentum about O in S1
108
117
if ~exist(' O' ,' var' )
109
118
O = anakin .point ; % default point
110
119
end
111
120
if exist(' S1' ,' var' )
112
- H = cross(P .pos0 - O .pos0 , P .p(S1 ));
121
+ H = cross(P .point . pos0 - O .pos0 , P .p(S1 ));
113
122
else
114
- H = cross(P .pos0 - O .pos0 , P .p );
123
+ H = cross(P .point . pos0 - O .pos0 , P .p );
115
124
end
116
125
end
117
126
function T = T(P ,S1 ) % kinetic energy in S1
118
127
if exist(' S1' ,' var' )
119
- vel = P .vel(S1 ).components;
128
+ vel = P .point . vel(S1 ).components;
120
129
else
121
- vel = P .vel .components ;
130
+ vel = P .point . vel .components ;
122
131
end
123
132
T = (P .mass / 2 ) * dot(vel ,vel );
124
133
end
125
134
function eqs = equations(P ,B1 ) % returns vector of equations of motion projected in basis B1
126
- MA = P .mass * P .accel ;
135
+ MA = P .mass * P .point . accel ;
127
136
F = anakin .tensor([0 ;0;0]); % allocate;
128
137
for i= 1 : length(P .forces )
129
138
F = F + P.forces{i };
@@ -142,15 +151,15 @@ function disp(P) % display
142
151
end
143
152
function inertia = inertia(P ,O ) % inertia tensor of the particle with respect to point O
144
153
if exist(' O' ,' var' )
145
- r = P .pos0 - O ;
154
+ r = P .point . coordinates - O . coordiantes ;
146
155
else
147
- r = P .pos0 ;
156
+ r = P .point . coordinates ;
148
157
end
149
158
inertia = P .mass * (norm(r )^2 * anakin .tensor(eye(3 )) - product(r ,r ));
150
159
end
151
160
function P_ = subs(P ,variables ,values ) % particularize symbolic vector
152
161
P_ = P ;
153
- P_.pos0 = P .pos0 .subs(variables ,values );
162
+ P_.point = P .point .subs(variables ,values );
154
163
P_.mass = P .mass .subs(variables ,values );
155
164
end
156
165
end
0 commit comments