hello Alberto
welcome back
I was first a bit puzzled because you speak of "line" whereas we are talking here "plane" that goes through 3 points. just a minor comment
also I don't see wich Fex function you refer to (missing link) but again this is not important
more important :
- 1 in your code you don't call the function plot_line_deviazione that you posted but this one : plot_line.
[normal0, d0, X0, Y0, Z0] = plot_line(A, B, C, -100, 100, -100, 100);
I supposed that it's actually plot_line_deviazione that you wanted to use in your main code
- now let's see what happen when you test your code with the following data (representing a triangle in the vertical plane)
A = [91.0049, 222.2614, -12.2419];
B = [12.8, 48.2, -5.6631];
C = [12.8, 48.2, -53.7279];
the cross product is a vector in the horizontal plane , so it's z coordinate is zero
normal = 1.0e+03 *( 8.3662 -3.7589 0)
therefore in this line you are making a division by zero resulting in Z being Inf :
Z = (-d - (normal(1)*X) - (normal(2)*Y))/normal(3);
so you have to check if your cross product has one zero value and make sure you are not making a division by zero when you generate the mesh.
for this specific case you have to create first the x and z plan mesh and then compute the Y result (see below new code of your function)
all the best
A = [91.0049, 222.2614, -12.2419];
B = [12.8, 48.2, -5.6631];
C = [12.8, 48.2, -53.7279];
plot3(A(:,1),A(:,2),A(:,3),'r.','Markersize',25)
plot3(B(:,1),B(:,2),B(:,3),'r.','Markersize',25)
plot3(C(:,1),C(:,2),C(:,3),'r.','Markersize',25)
[normal0, d0, X, Y, Z] = plot_line_deviazione(A, B, C, -100, 100, -100, 100);
function [normal, d, X, Y, Z] = plot_line_deviazione(p1, p2, p3, x_min, x_max, y_min, y_max)
normal = cross(p1 - p2, p1 - p3);
d = p1(1)*normal(1) + p1(2)*normal(2) + p1(3)*normal(3);
Z = (-d - (normal(1)*X) - (normal(2)*Y))/(normal(3));
z = min([p1(3) p2(3) p3(3)]):max([p1(3) p2(3) p3(3)]);
Y = (-d - (normal(1)*X) - (normal(3)*Z))/(normal(2));