/ simulated_instruments / triangle
Sign in
simulated_instruments / triangle
triangle / matlab / triangle_geometry.m
63 lines · 1.8 KBBlameHistoryRaw
1function G = triangle_geometry(P)
2% TRIANGLE_GEOMETRY Node polyline of the open triangle centerline.
3%
4% An equilateral triangle of side side_length_m in the x-y plane, apex up:
5% base from V2 (bottom left) to V3 (bottom right) along y = 0, apex V1 above
6% the origin. The rod is open at the bottom-left corner: gap_m of arclength
7% is removed there, half from the base and half from the left leg, so the
8% centerline runs A -> V3 -> V1 -> B counterclockwise, where A and B sit
9% gap_m / 2 from V2 along their legs. Total rod length is 3 L - gap.
11% The polyline is discretized into about n_elements equal-length elements,
12% with the two closed corners landing exactly on nodes. Arclength fraction 0
13% is the free end on the base, 1 the free end on the left leg; strike_pos and
14% roll_pos2 are expressed in this coordinate.
16% Returns G with:
17% nodes 2 x nn node coordinates (m)
18% sfrac 1 x nn arclength fraction of each node
19% totalLen rod arclength (m)
20% nn, ne node count and per-leg element counts (1 x 3)
22L = P.side_length_m;
23g = min(P.gap_m, 0.8 * L);
24V1 = [0; L * sqrt(3) / 2];
25V2 = [-L / 2; 0];
26V3 = [L / 2; 0];
27e1 = (V3 - V2) / L;
28e3 = (V2 - V1) / L;
29A = V2 + e1 * (g / 2);
30B = V2 - e3 * (g / 2);
32starts = [A, V3, V1];
33stops = [V3, V1, B];
34lens = [L - g / 2, L, L - g / 2];
35total = lens(1) + lens(2) + lens(3);
37ne = zeros(1, 3);
38for k = 1:3
39 ne(k) = max(2, round(P.n_elements * lens(k) / total));
40end
41nn = ne(1) + ne(2) + ne(3) + 1;
43nodes = zeros(2, nn);
44sarc = zeros(1, nn);
45nodes(:, 1) = A;
46idx = 1;
47acc = 0;
48for k = 1:3
49 for j = 1:ne(k)
50 idx = idx + 1;
51 frac = j / ne(k);
52 nodes(:, idx) = starts(:, k) + (stops(:, k) - starts(:, k)) * frac;
53 sarc(idx) = acc + lens(k) * frac;
54 end
55 acc = acc + lens(k);
56end
58G.nodes = nodes;
59G.sfrac = sarc / total;
60G.totalLen = total;
61G.nn = nn;
62G.ne = ne;
63end
↑↓ move↵openescclose