Skip to content

Commit

Permalink
Add faster cross function alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
ybeyer committed Jun 21, 2022
1 parent c53b8a8 commit 96d8610
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions operations/crossFast.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function c = crossFast(a,b)
% crossFast faster implementation of cross function
% This function only works for 3xN array inputs but is much faster
% compared to cross.
%
% Syntax:
% c = crossFast( a, b )
%
% Inputs:
% a first vectors (3xN array)
% b second vectors (3xN array)
%
% Outputs:
% c product of inputs (3xN array)
%
% See also:
% cross

% Disclamer:
% SPDX-License-Identifier: GPL-2.0-only
%
% Copyright (C) 2022 Yannic Beyer
% Copyright (C) 2022 TU Braunschweig, Institute of Flight Guidance
% *************************************************************************

% Calculate cross product
c(3,:) = a(1,:).*b(2,:)-a(2,:).*b(1,:);
c(1,:) = a(2,:).*b(3,:)-a(3,:).*b(2,:);
c(2,:) = a(3,:).*b(1,:)-a(1,:).*b(3,:);

end

0 comments on commit 96d8610

Please sign in to comment.