diff --git a/MOT Capture Process Simulation/+Helper/calculateDistanceFromPointToLine.m b/MOT Capture Process Simulation/+Helper/calculateDistanceFromPointToLine.m new file mode 100644 index 0000000..45a1244 --- /dev/null +++ b/MOT Capture Process Simulation/+Helper/calculateDistanceFromPointToLine.m @@ -0,0 +1,10 @@ +function ret = calculateDistanceFromPointToLine(p0 , p1, p2) + p01 = p0 - p1; + p12 = p2 - p1; + CrossProduct = [p01(2)*p12(3) - p01(3)*p12(2), p01(3)*p12(1) - p01(1)*p12(3), p01(1)*p12(2) - p01(2)*p12(1)]; + ret = rssq(CrossProduct) / rssq(p12); + + %Height of parallelogram (Distance between point and line) = Area of parallelogram / Base + %Area = One side of parallelogram X Base + %ret = norm(cross(one side, base))./ norm(base); +end \ No newline at end of file diff --git a/MOT Capture Process Simulation/+Helper/findAllZeroCrossings.m b/MOT Capture Process Simulation/+Helper/findAllZeroCrossings.m new file mode 100644 index 0000000..4b8d9db --- /dev/null +++ b/MOT Capture Process Simulation/+Helper/findAllZeroCrossings.m @@ -0,0 +1,18 @@ +function ret = findAllZeroCrossings(x,y) +% Finds all Zero-crossing of the function y = f(x) + zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector + zxidx = zci(y); + if ~isempty(zxidx) + for k1 = 1:numel(zxidx) + idxrng = max([1 zxidx(k1)-1]):min([zxidx(k1)+1 numel(y)]); + xrng = x(idxrng); + yrng = y(idxrng); + [yrng2, ~, jyrng] = unique(yrng); %yrng is a new array containing the unique values of yrng. jyrng contains the indices in yrng that correspond to the original vector. yrng = yrng2(jyrng) + xrng2 = accumarray(jyrng, xrng, [], @mean); %This function creates a new array "xrng2" by applying the function "@mean" to all elements in "xrng" that have identical indices in "jyrng". Any elements with identical X values will have identical indices in jyrng. Thus, this function creates a new array by averaging values with identical X values in the original array. + ret(k1) = interp1( yrng2(:), xrng2(:), 0, 'linear', 'extrap' ); + end + else + warning('No zero crossings found!') + ret = nan; + end +end \ No newline at end of file