% TestTrackRotationAngle_MultiSpan.m % Script to test calculation of trackRotationAngle…
- User
% TestTrackRotationAngle_MultiSpan.m % Script to test calculation of trackRotationAngle and track adjustment with more spans and plot vectors
clc; clear; close all;
spanCount = 10; % More spans
% Create dummy spans with varying data for i = 1:spanCount spans(i).LeftEnd.Stagger = 0.02 * sin(i/2); % stagger oscillates spans(i).RightEnd.Stagger = 0.03 * cos(i/3); spans(i).LeftEnd.ContactHeight = 0.15 + 0.005i; % slowly increasing contact height spans(i).RightEnd.ContactHeight = 0.15 + 0.005i; spans(i).LeftEnd.TrackZ = 0.05 * i; % linearly increasing Z offset spans(i).RightEnd.TrackZ = 0.05 * i; spans(i).LeftEnd.Cant = 0.01 * sin(i/4); % cant oscillates slowly spans(i).RightEnd.Cant = 0.02 * cos(i/5); spans(i).SpanType = 1; % normal span spans(i).StructureIDstart = sprintf('Span_%d', i); end
% Dummy registrations - create registration points along a simple curve registrations = cell(spanCount,1); CW = cell(spanCount,1); for i = 1:spanCount % Generate 3 points for each registration forming a small curve segment t = linspace(0, 1, 3)'; x = i + 0.5 * t; % X increments along i with small segment length y = sin(i/2) + 0.3*t; % Y oscillates slowly + small increments z = zeros(3,1); % flat for simplicity registrations{i} = [x y z]; CW{i} = [x y z]; end
trackOrigin = [0 0 0]; instancePosition = [];
% Helper functions CantRotationMatrix = @(cant) [cos(cant) -sin(cant) 0; sin(cant) cos(cant) 0; 0 0 1]; SpanRotationMatrix = @(angle) [cos(angle) -sin(angle) 0; sin(angle) cos(angle) 0; 0 0 1]; CantAngle = @(cant) cant;
track = zeros(spanCount, 6); RAname = cell(spanCount,1);
figure; hold on; axis equal; title('Track Registration Directions and Adjusted Positions'); xlabel('X'); ylabel('Y');
colors = lines(spanCount);
for regIndex = 1:spanCount registration = registrations{regIndex};
code - Assistant
- User
i want to calculate the perpendicular direction of the connection of the 2 spans, i dont know if this line of codes helps you v1 = regDirection_current; % direction vector of current span (2D) v2 = regDirection_next; % direction vector of next span (2D)
cosTheta = dot(v1, v2) / (norm(v1)*norm(v2)); angleBetween = acosd(max(min(cosTheta, 1), -1)); % angle in degrees, clamped for safety
- Assistant