# comparing and cross product

2 views (last 30 days)
Oday Shahadh on 8 Jun 2020
Answered: Walter Roberson on 8 Jun 2020
hi guys,
why c in below return with one coulmn, it supposed to return (x,y,z,) vector?
regards
c=zeros[];
for i=1:length(p)
if (L1(i,3)==p(i,3))
c=[c,cross(L1(i,:),p(i,:))];
end
end
##### 2 CommentsShowHide 1 older comment
Oday Shahadh on 8 Jun 2020
I two arrays A(x1,y2,z1), and B(x2,y2,z2).
I need to cross product between one row from A with all rows in B which have same z value.
for instance
a(1,2,3)
-------
b(2,4,5)
b(2,2,3)
b(7,5,9)
b(5,8,3)
cross(a,b) in case a(i,3)=b(i,3)
---------------------------------------------------------------
script:
clear
close all
format long
x=[];
y=[];
z=[];
for L=-2:0.5:2
for r=0:.5:2
for theta=0:45:360;
x=[x;r*cos(theta*pi/180)];
y=[y;r*sin(theta*pi/180)];
z=[z,L];
L1=[x-x,x-x,z'];
end
end
end
lx=L1(:,1);ly=L1(:,2);lz=L1(:,3);
z=z';
p=[x,y,z];
b=cross(L1(1,:),p(1,:));
c=zeros[];
for i=1:length(p)
if (L1(i,3)==p(i,3))
c=[c,cross(L1(i,:),p(i,:))];
end
end
figure(1)
plot3(x,y,z);hold on
plot3(lx,ly,lz,'r');hold on

Walter Roberson on 8 Jun 2020
Your first column of L1 is derived from something minus itself, so the first column is going to be all 0.
Your second column of L1 is derived from something minus itself, so the second column is going to be all 0.
Cross-product of [0; 0; something] and [0; 0; something_else] is always going to be 0
>> syms x1 x2 y1 y2
>> cross([x1;y1;z1],[x2;y2;z2])
ans =
y1*z2 - y2*z1
x2*z1 - x1*z2
x1*y2 - x2*y1
but your x1 and x2 and y1 and y2 are all 0, and every term involves one of those variables, so every term is going to come out 0. Therefore your cross-product will come out 0 .