Intersection points of generated lines and polygon
Show older comments
I have a script (below) that generates two plots: a set of points that represent a cross_section of a 3D surface (blue) and a set of fixed, set angle lines (red)
vv = Cross_sections;
cla
hold on
for k = 1:1 %length(Cross_sections)
x = [vv{k}(:,1); vv{k}(1,1)];
y = [vv{k}(:,2); vv{k}(1,2)];
z = [vv{k}(:,3); vv{k}(1,3)];
plot3(x,y,z,'.-b');
N = length(x);
% use 3 points to calculate normal vector of crossection plane
i1 = 1; % first index
i2 = round(N/3); % second index
i3 = round(2*N/3); % third index
v1 = [x(i1)-x(i2) y(i1)-y(i2) z(i1)-z(i2)];
v2 = [x(i1)-x(i3) y(i1)-y(i3) z(i1)-z(i3)];
v = cross(v1,v2); % normal vector of a plane
a = v(1); b = v(2); c = v(3);
% use normal vector to find approximate centroid
x0 = (max(x)+min(x))/2; % approximate centroid X
y0 = (max(y)+min(y))/2; % approximate centroid Y
% use a(px-x0) + b(py-y0) + c(pz-z0) == 0
% equation to find centroid Z
% choose first point for (px, py, pz)
z0 = (a*(x(1)-x0) + b*(y(1)-y0))/c + z(1);
% circle
R = 10;
ac = sqrt(a*a+c*c);
abc = sqrt(a*a+b*b+c*c);
t1 = linspace(0,2*pi,62);
ct = cos(t1);
st = sin(t1);
x1 = x0 + R/ac*(c*ct-a*b*st/abc);
y1 = y0 + R*ac/abc*st;
z1 = z0 - R/ac*(a*ct+b*c*st/abc);
% draw lines
for i = 1:length(x1)
plot3([x0 x1(i)],[y0 y1(i)],[z0 z1(i)],'.-r')
end
end
hold off

Question: Could someone please give me some guidance so as to generate or incorporate a script into MY script in order to generate the intersection points of the blue lines with the red lines. Perhaps the intersection points to be stored and also plotted on the same figure as an asterix or so.
Thank you!!
1 Comment
Arvin Rasoulzadeh
on 10 Jun 2022
I noticed that your "pencil of lines" and your "blue curve" are planar. Therefore, you can find the carrier plane of them and with a suitable rotation (and translation) make it coincide with xy-plane. From then you can use polyxpoly command in the following way:
for i = 1:length(x1)
[p1{i},p2{i}] = polyxpoly([x0, x1(i)],[y0,y1(i)],x,y);
end
pp1 = cell2mat(p1);
pp2 = cell2mat(p2);
hold on
axis equal
plot(pp1',pp2',zeros(numel(pp1),1),'g-');
hold off
Which the result will be:

Accepted Answer
More Answers (0)
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
