Effacer les filtres
Effacer les filtres

Why won't my line functions display their lines?

1 vue (au cours des 30 derniers jours)
Emma Williston
Emma Williston le 11 Avr 2018
Commenté : Walter Roberson le 11 Avr 2018
This function takes in x-, y- and z-coordinates of a plane from X, Y, and Z. Then it imports the coordinates of a cube (centered over the origin) and is supposed to plot a parallel projection of the cube onto the plane (using the point on the plane that I calculate here).
I can't figure out why my line functions at the end won't work, when the ones I use for my drawCuboid() function work just fine.
function drawParProjCuboid(X,Y,Z)
%draw parallel projection of cuboid on oblique plane
%figure;
hold on;
%plane points are within X, Y, & Z
%Get cube points
fid=fopen('inFileCub.txt','r');
R=fscanf(fid,'%f');
for i=1:24
if i>=1 && i<=8
x(i)=R(i);
end
if i>=9 && i<=16
y(i-8)=R(i);
end
if i>=17 && i<=24
z(i-16)=R(i);
end
end
CP1=[x(1);y(1);z(1)];
CP2=[x(2);y(2);z(2)];
CP3=[x(3);y(3);z(3)];
CP4=[x(4);y(4);z(4)];
CP5=[x(5);y(5);z(5)];
CP6=[x(6);y(6);z(6)];
CP7=[x(7);y(7);z(7)];
CP8=[x(8);y(8);z(8)];
%(x-x1)/l = (y-y1)/m = (z-z1)/n
%find point on plane: (x1,y1,z1)
x1=(X(1)-2); y1=(Y(1)-2);
Ax=X(1); Ay=Y(1); Az=Z(1);
Bx=X(2); By=Y(2); Bz=Z(2);
Cx=X(3); Cy=Y(3); Cz=Z(3);
z1a = (Bx-Ax)*(Cz-Az)-(Cx-Ax)*(Bz-Az);
z1b = (Bx-Ax)*(Cy-Ay)-(Cx-Ax)*(By-Ay);
z1c = (By-Ay)*(Cz-Az)-(Cy-Ay)*(Bz-Az);
z1d = (Bx-Ax)*(Cy-Ay)-(Cx-Ax)*(By-Ay);
z1 = Az+(y-Ay)*z1a/z1b-(x-Ax)*z1c/z1d;
%z1=Az+(((Bx-Ax)(Cz-Az)-(Cx-Ax)(Bz-Az))/((Bx-Ax)(Cy-Ay)-(Cx-Ax)(By-Ay)))(y1-Ay)-...
% (((By-Ay)(Cz-Az)-(Cy-Ay)(Bz-Az))/((Bx-Ax)(Cy-Ay)-(Cx-Ax)(By-Ay)))(x1-Ax);
%direction vector
d=[(x1-CP1(1)),(y1-CP1(2)),(z1-CP1(3))];
% This plane's equation:
% t = (x-CP1(1))/d(1) = (y-CP1(2))/d(2) = (z-CP1(3))/d(3)
% PP#(x) = (y1-CP#(2))d(1)/d(2)
% PP#(y) = (z1-CP#(3))d(2)/d(3)
% PP#(z) = (x1-CP#(1))d(3)/d(1)
%Find all parallel-projected point values:
XP=[(d(1)*(y1-CP1(2))/d(2)),(d(1)*(y1-CP2(2))/d(2)),(d(1)*(y1-CP3(2))/d(2)),...
(d(1)*(y1-CP4(2))/d(2)),(d(1)*(y1-CP5(2))/d(2)),(d(1)*(y1-CP6(2))/d(2)),...
(d(1)*(y1-CP7(2))/d(2)),(d(1)*(y1-CP8(2))/d(2))];
YP=[(d(2)*(z1-CP1(3))/d(3)),(d(2)*(z1-CP2(3))/d(3)),(d(2)*(z1-CP3(3))/d(3)),...
(d(2)*(z1-CP4(3))/d(3)),(d(2)*(z1-CP5(3))/d(3)),(d(2)*(z1-CP6(3))/d(3)),...
(d(2)*(z1-CP7(3))/d(3)),(d(2)*(z1-CP8(3))/d(3))];
ZP=[(d(3)*(x1-CP1(1))/d(1)),(d(3)*(x1-CP2(1))/d(1)),(d(3)*(x1-CP3(1))/d(1)),...
(d(3)*(x1-CP4(1))/d(1)),(d(3)*(x1-CP5(1))/d(1)),(d(3)*(x1-CP6(1))/d(1)),...
(d(3)*(x1-CP7(1))/d(1)),(d(3)*(x1-CP8(1))/d(1))];
figure;
line([XP(1) XP(5)],[YP(1) YP(5)],[ZP(1) ZP(5)],'color','m');
line([XP(1) XP(2)],[YP(1) YP(2)],[ZP(1) ZP(2)],'color','m');
line([XP(1) XP(4)],[YP(1) YP(4)],[ZP(1) ZP(4)],'color','m');
line([XP(7) XP(6)],[YP(7) YP(6)],[ZP(7) ZP(6)],'color','m');
line([XP(7) XP(8)],[YP(7) YP(8)],[ZP(7) ZP(8)],'color','m');
line([XP(7) XP(3)],[YP(7) YP(3)],[ZP(7) ZP(3)],'color','m');
line([XP(5) XP(6)],[YP(5) YP(6)],[ZP(5) ZP(6)],'color','m');
line([XP(5) XP(8)],[YP(5) YP(8)],[ZP(5) ZP(8)],'color','m');
line([XP(4) XP(3)],[YP(4) YP(3)],[ZP(4) ZP(3)],'color','m');
line([XP(4) XP(8)],[YP(4) YP(8)],[ZP(4) ZP(8)],'color','m');
line([XP(2) XP(3)],[YP(2) YP(3)],[ZP(2) ZP(3)],'color','m');
line([XP(2) XP(6)],[YP(2) YP(6)],[ZP(2) ZP(6)],'color','m');
end
  1 commentaire
Walter Roberson
Walter Roberson le 11 Avr 2018
Check for nan and inf in the coordinates.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by