Intersection of two linear lines in 3D

I have 3 data sets:A,B and C.I have plotted A vs B and C vs B. Now I want to plot a 3D graph which will represent the intersection of these two lines.How it can be done in Matlab,any help?

 Accepted Answer

Jon
Jon on 22 Jul 2019
Edited: Jon on 22 Jul 2019
It is a little hard to follow from your desription but I'm assuming you have 2 three dimensional curves that intersect.
So each curve is a set of points in 3-D space, where each point is given by an x,y and z coordinate value. Suppose you have m data points for each curve. Let the points in curve 1 be given by an m by 3 matrix, C1, where the first column is the x coordinate values, the second column is the y coordinate values, and the third column is the z coordinate values. Similarly let the points in the second curve be given by a m by 3 matrix C2 then you can use:
plot3(C1(:,1),C1(:,2),C1(:,3))
hold on
plot3(C2(:,1),C2(:,2), C2(:,3))

7 Comments

phoenix
phoenix on 23 Jul 2019
Edited: phoenix on 23 Jul 2019
Thanks@ Jon for your reply. I have two curves which are two dimensional,linear variation. I want to plot the two curves on the common axis of B in 3D.
A=[0.08 0.10 0.14 0.18];
B=[0 0 0.1137 0.02104];
C=[0.00173 0.00277 0.062503 0.00978];
I saw the 'fplot3' command to plot multiple lines on the same axis in Matlab.Can it be done by this command and how?
Looking at the documentation for fplot3 https://www.mathworks.com/help/matlab/ref/fplot3.html you can see that this is for the situation where you have a parametric curve, in the 3d x,y, z coordinate system defined by 3 functions which give respectively x(t), y(t), z(t) where t is the parameter. In your case you just have data, so this doesn't seem appropriate for your situation.
I am also unclear about what you are trying to plot. You say you want to plot the two curves on the common axis of B. You also say that they are "linear variation" which I would interpret as meaning that is A is a linear function of B, and C is a linear function of B. So for example something like A = m*B + b where m and b are constants. Your data however is not consistent with this interpretation. The first two elements of B are both zero, however the first two elements of A are not the same as they must be if A were a linear function of B. Similarly the first two elements of C are not the same and they must be if C were a linear function of B.
Ignoring all of that, if you simply are saying that you have some data points in the A-B plane, and some other data points in the C-B plane and you want to plot all of them in the 3-D A,B,C coordinate system then you can do this
% define vector of zeros to be used as the 3rd coordinate for points in either the
% the A-B plane or in the C-B plane
Z = zeros(size(B))
% now plot the points in the 3-D A,B,C coordinate system
%plot the points in the A-B plane (C=0)
plot3(A,B,Z)
hold on % plot the next points on the same axes
%
% plot the points in the C-B plane (A=0)
plot3(Z,B,C)
hold off
Or maybe I am misinterpeting what you mean by plotting against common axis B, and the you just want to plot the points given in vectors A,B,C in the A,B,C coordinate system in which case you could just use
plot3(A,B,C)
I want to plot something like this (attached figure). Any help?
This will make a plot similar to the one you show.
% define curves
% make a matrix for each curve
% columns of matrices are x,y,z coordinates
C1 = [...
0.980 0.20 0.010;
0.982 0.25 0.02;
0.984 0.30 0.03;
0.986 0.35 0.04;
0.988 0.40 0.05;
0.990 0.45 0.06]
C2 = [...
0.988 0.250 0.020;
0.986 0.275 0.025;
0.984 0.300 0.030;
0.982 0.325 0.035;
0.980 0.350 0.040;
0.978 0.375 0.045]
% plot the points
plot3(C1(:,1),C1(:,2),C1(:,3),'Marker','square')
hold on
plot3(C2(:,1),C2(:,2),C2(:,3),'Marker','x')
hold off
grid
xlim([0.96,1])
ylim([0.1,0.5])
zlim([0.01 0.06])
xlabel('Coupling Coefficient (k4)');
ylabel('Coupling Coefficient (k1)');
zlabel('Crosstalk')
Did this answer your question?
Thanks a lot @Jon. It worked.
Very good. Glad you were able to get it working.

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 22 Jul 2019

Commented:

Jon
on 31 Jul 2019

Community Treasure Hunt

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

Start Hunting!