Skip to content

Commit 373f60d

Browse files
authored
Added TRI(N) and TOTAL_POLYLINE_LENGTH(P) code macros (#997)
1 parent 7a08167 commit 373f60d

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Body/AAUHuman/BodyModels/GenericBodyModel/Helper.ClassTemplates.any

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
// Pairwise distances between observations in n-dimensional space.
2929
#define PDIST(X) sum(vnorm(DIFFMAT(SizesOf(X)[0])*(X)))
3030

31+
//Total length of a polyline defined by a set of points.
32+
#define TOTAL_POLYLINE_LENGTH(P) sum(vnorm((arrcat(zeros(1,SizesOf(P)[0]-1), eye(SizesOf(P)[0]-1)')' - arrcat(eye(SizesOf(P)[0]-1)', zeros(1,SizesOf(P)[0]-1))')*P))
33+
34+
//An array with ones at and below the given diagonal and zeros elsewhere.
35+
#define TRI(N) lteqfun(transpose(repmat(1,N ,iarr(1,N))), repmat(1,N,iarr(1,N)))
36+
3137
// Upper triangle of the array. Return a copy of an array with elements below the diagonal zeroed out
3238
#define TRIU(IN) mult(IN, gteqfun(transpose(repmat(1,SizesOf(IN)[0] ,iarr(1,SizesOf(IN)[1]))), repmat(1,SizesOf(IN)[1],iarr(1,SizesOf(IN)[0]))))
3339

@@ -36,8 +42,6 @@
3642

3743

3844

39-
40-
4145
// Projection of P onto the line BA
4246
#define VECTOR_PROJECTION(P, A, B) (A) + ( ((P)-(A))*((B)-(A))' / ( ((B)-(A))*((B)-(A))') )*((B)-(A))
4347
// Normal vector for the non-coliniar points A,B,C

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* Added a small class template, [`CreateCoMRefNode`](#Utilities.center-of-mass.createcomrefnode.createcomrefnode),
1111
that can be used to create a reference node at the center of mass of a segment with its axes aligned with
1212
the principal axes of inertia of the segment.
13+
* Added a `TRI(N)` helper code macros which creates a lower triangular (NxN) matrix.
14+
* Added a `TOTAL_POLYLINE_LENGTH(P)` helper code macro which calculates the total length of a polyline defined by a set of points.
1315

1416
### 🩹 Fixed:
1517
* Fixed an issue that prevented switching off drawing of marker arrows in CreateMarkerDriverClass in MoCap models. Updated the search string

Tests/test_helper_templates.any

+22-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,28 @@ Main =
6262
AnyFloat length = PDIST(Mat);
6363
AnyInt test = assert(eqfun(PDIST(Mat), 2*sqrt(3)));
6464
};
65-
AnyFolder Test_TRIU_TRIL = {
65+
66+
AnyFolder Test_TOTAL_POLYLINE_LENGTH ={
67+
AnyFloat P = {
68+
{0,0,0},
69+
{1,0,0},
70+
{1,1,0},
71+
{1,1,1}
72+
};
73+
AnyFloat length = TOTAL_POLYLINE_LENGTH(P);
74+
AnyInt test = assert(eqfun(length, 3));
75+
};
76+
77+
AnyFolder Test_TRIU_TRIL_TRI = {
78+
79+
AnyFloat test_TRI = assert(
80+
eqfun(TRI(4),
81+
{{1.0, 0.0, 0.0, 0.0},
82+
{1.0, 1.0, 0.0, 0.0},
83+
{1.0, 1.0, 1.0, 0.0},
84+
{1.0, 1.0, 1.0, 1.0}}
85+
)
86+
);
6687

6788
AnyFloat M_wide = ones(3,5);
6889
AnyFloat M_tall = ones(6,3);

0 commit comments

Comments
 (0)