-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstraint_forces_torques.m
76 lines (56 loc) · 2.13 KB
/
constraint_forces_torques.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function [FX, FY, TAUZ] = constraint_forces_torques(FX_IN, FY_IN, ...
TAUZ_IN, TX, TY, LAMBDA1, LAMBDA2, SW_IND, DL_SW)
% CONSTRAINT_FORCES_TORQUES Adds constraint forces and torques to
% filaments.
%
% [FX, FY, TAUZ] = constraint_forces_torques(FX_IN, FY_IN, TAUZ_IN,...
% TX, TY, LAMBDA1, LAMBDA2,...
% SW_IND, DL_SW)
% takes in current forces and torques [FX_IN, FY_IN, TAUZ_IN], tangent
% vectors [TX,TY], constraints [LAMBDA1, LAMBDA2], filament indexing
% matrix SW_IND and segment separation matrix DL_SW.
%
% The function returns the constraint forces and torques + any existing
% forces and torques.
%
% These expressions correspond to F^C and T^C, equations (16) and (17)
% in the paper.
FX = FX_IN;
FY = FY_IN;
TAUZ = TAUZ_IN;
N_sw = size(SW_IND,1);
N_w = size(SW_IND,2);
N_lam = N_w - 1;
for i=1:N_sw
jlam_st = (i-1)*N_lam;
jlam = jlam_st + 1;
jsw = SW_IND(i,1);
ksw = SW_IND(i,2);
DL = DL_SW(i,1);
lam1 = LAMBDA1(jlam);
lam2 = LAMBDA2(jlam);
FX(ksw) = FX(ksw) + lam1;
FY(ksw) = FY(ksw) + lam2;
FX(jsw) = FX(jsw) - lam1;
FY(jsw) = FY(jsw) - lam2;
tempx = -0.5*DL*lam1;
tempy = -0.5*DL*lam2;
TAUZ(ksw) = TAUZ(ksw) + (TX(ksw)*tempy - TY(ksw)*tempx);
TAUZ(jsw) = TAUZ(jsw) + (TX(jsw)*tempy - TY(jsw)*tempx);
for j=2:N_lam
jlam = jlam_st + j;
jsw = SW_IND(i,j);
ksw = SW_IND(i,j+1);
DL = DL_SW(i,j);
lam1 = LAMBDA1(jlam);
lam2 = LAMBDA2(jlam);
FX(ksw) = FX(ksw) + lam1;
FY(ksw) = FY(ksw) + lam2;
FX(jsw) = FX(jsw) - lam1;
FY(jsw) = FY(jsw) - lam2;
tempx = -0.5*DL*lam1;
tempy = -0.5*DL*lam2;
TAUZ(ksw) = TAUZ(ksw) + (TX(ksw)*tempy - TY(ksw)*tempx);
TAUZ(jsw) = TAUZ(jsw) + (TX(jsw)*tempy - TY(jsw)*tempx);
end
end