How do show points on plane going through 3d plot

11 Ansichten (letzte 30 Tage)
Simon Spielmann
Simon Spielmann am 29 Apr. 2023
Kommentiert: Simon Spielmann am 30 Apr. 2023
Hello,
I have 3d plot of points and curves which are connected (picture attached). ("o" and "*" in the graph are my points in matrix and "-" & "--" connect the points)
Then I make a new "plane" (gray color) going through the graph. I need to show points of curves going through the plane on the plane.
Is there a way make a plane goint through curves and then show and write points of the curves?

Antworten (2)

albara
albara am 29 Apr. 2023
Yes, you can create a plane that intersects the 3D curves and then display the intersection points on the plane. I will provide a general outline of the steps you can take to achieve this in MATLAB.
  1. Define your 3D points and curves.
  2. Define the plane equation (e.g., Ax + By + Cz + D = 0).
  3. Find intersection points between the plane and the curves.
  4. Plot the points and curves in a 3D plot.
  5. Plot the intersection points on the plane.
Here's an example to help you get started:
% Define your 3D points and curves (dummy example)
curve1 = [1 2 3; 2 3 4; 3 4 5];
curve2 = [5 4 3; 4 3 2; 3 2 1];
% Define the plane equation: Ax + By + Cz + D = 0
A = 1;
B = 1;
C = 1;
D = -6;
% Find intersection points between the plane and the curves
intersect1 = intersectPlaneCurve(A, B, C, D, curve1);
intersect2 = intersectPlaneCurve(A, B, C, D, curve2);
% Plot the points and curves in a 3D plot
figure
hold on
plot3(curve1(:,1), curve1(:,2), curve1(:,3), 'o-')
plot3(curve2(:,1), curve2(:,2), curve2(:,3), 'o--')
plotIntersectionPlane(A, B, C, D)
% Plot the intersection points on the plane
scatter3(intersect1(:,1), intersect1(:,2), intersect1(:,3), 'r*')
scatter3(intersect2(:,1), intersect2(:,2), intersect2(:,3), 'g*')
hold off
function intersection = intersectPlaneCurve(A, B, C, D, curve)
intersection = [];
for i = 1:size(curve, 1)-1
p1 = curve(i,:);
p2 = curve(i+1,:);
[is_intersect, point] = linePlaneIntersection(A, B, C, D, p1, p2);
if is_intersect
intersection = [intersection; point];
end
end
end
function [is_intersect, point] = linePlaneIntersection(A, B, C, D, p1, p2)
direction = p2 - p1;
denominator = A*direction(1) + B*direction(2) + C*direction(3);
if abs(denominator) < 1e-6
is_intersect = false;
point = [];
return
end
t = -(A*p1(1) + B*p1(2) + C*p1(3) + D) / denominator;
point = p1 + t * direction;
if t >= 0 && t <= 1
is_intersect = true;
else
is_intersect = false;
point = [];
end
end
function plotIntersectionPlane(A, B, C, D)
[x, y] = meshgrid(linspace(-10, 10, 100));
z = (-D - A*x - B*y) / C;
surf(x, y, z, 'FaceAlpha', 0.5, 'EdgeColor', 'none', 'FaceColor', [0.5 0.5 0.5]);
end
This example shows two 3D curves and a plane that intersects them.
Important: There may be some mistakes in this answer Experts can tell if there are any mistakes
  3 Kommentare
albara
albara am 30 Apr. 2023
Bearbeitet: albara am 30 Apr. 2023
You are welcome, Yes, you can determine the position of the plane by adjusting the coefficients A, B, C, and D of the plane equation Ax + By + Cz + D = 0. If you have a normal vector n = [A; B; C] and a point on the plane p = [x0; y0; z0], you can find the value of D as follows:
D = -A * x0 - B * y0 - C * z0
In your example, you want a plane parallel to the YZ plane (normal vector n = [1; 0; 0]) and positioned at x = -10. To find D, you can use any point on the plane, for instance, p = [-10; 0; 0]:
D = -1 * (-10) - 0 * 0 - 0 * 0 = 10
So, your plane equation is x + 10 = 0, or equivalently, 1x + 0y + 0z + 10 = 0.
In the provided MATLAB code, you can set A, B, C, and D as follows:
A = 1; B = 0; C = 0; D = 10;
This will create a plane parallel to the YZ plane at x = -10.
Important: There may be some mistakes in this answer Experts can tell if there are any mistakes
Simon Spielmann
Simon Spielmann am 30 Apr. 2023
Thank You very much again for explanation!
Helped me a lot

Melden Sie sich an, um zu kommentieren.


chicken vector
chicken vector am 29 Apr. 2023
Not sure if I understood what you need.
You can have plane transparency using 'FaceAlpha'.
Is this helpful? Otherwise I ask you for more details.
nCurves = 10;
nPoints = 15;
xPlane = 5;
x = 0 : nPoints-1;
y = (1 : nCurves)' + rand(nCurves,nPoints)/2;
z = flip(x) + rand(nCurves,nPoints);
lineStyles = {'-o','--*'};
figure;
grid on;
hold on;
for line = 1 : nCurves
plot3(x,y(line,:),z(line,:),lineStyles{round((line-1)/nCurves)+1});
end
fill3(xPlane*ones(4,1), [-2, nPoints*2, nPoints*2, -2], [-2, -2, nPoints*2, nPoints*2], ...
[.85 .85 .85],'FaceAlpha',0.85)
hold off;
view([2 1 1]);
xlabel('x'); ylabel('y'); zlabel('z');
xlim([-1 nPoints-1]); ylim([-1 nCurves+1]); zlim([0 nPoints*1.5]);
  1 Kommentar
Simon Spielmann
Simon Spielmann am 30 Apr. 2023
Thank you for your respond.
My problem is I would like to determine plane in the 3d plot and then show on the plane intersect point of curves going through the plane.
albara understood my problem and gave me solution to my problem

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by