MATLAB - How to project an sphere/hemisphere to any planes?

조회 수: 3 (최근 30일)
viet le
viet le 2016년 8월 27일
답변: Aniket 2025년 4월 8일
I have objects as a figure attached. I want to project objects (blue color and small red color) to plane (yellow color) follow perpendicular.
I can project object to coordinate plane (oxy, oyz, oxz) by command: surf(x,y,0*z), surf(0*x,y,z), surf(x,0*y,z). How to project to any plane?
Thank
  댓글 수: 2
viet le
viet le 2016년 8월 27일
this is 2D projected figure when project to plan ozx
Jianshe Feng
Jianshe Feng 2019년 1월 29일
Did you get this solved? I have the same question now.

댓글을 달려면 로그인하십시오.

답변 (1개)

Aniket
Aniket 2025년 4월 8일
To project 3D objects (such as your blue and red shapes) onto an arbitrary plane (like the yellow one shown in your figure) perpendicularly, you'll need to use a vector-based approach.
Assume the plane is defined by:
A point on the plane: P0 = [x0, y0, z0]
A normal vector: n = [A, B, C]
Then for any 3D point P = [x, y, z], the perpendicular projection onto the plane is computed as:
n = n / norm(n); % Normalize the normal vector
d = dot(n, (P - P0)); % Distance from point to plane along the normal
P_proj = P - d * n; % Projected point on the plane
This can be done efficiently for an entire set of points representing your objects.
% Define the plane
plane_point = [0, 0, 0]; % A point on the plane
plane_normal = [1, 1, 1]; % Normal vector to the plane
% Sample object: a sphere
[x, y, z] = sphere(20);
x = x(:); y = y(:); z = z(:); % Convert to point list
% Combine points into a matrix
points = [x, y, z];
% Normalize normal vector
n = plane_normal / norm(plane_normal);
% Compute perpendicular projection for each point
distances = (points - plane_point) * n';
projected_points = points - distances .* n;
% Plot original and projected points
figure;
scatter3(points(:,1), points(:,2), points(:,3), 'b.'); hold on;
scatter3(projected_points(:,1), projected_points(:,2), projected_points(:,3), 'r.');
legend('Original Points', 'Projected Points');
% Optionally: Plot the projection plane
[xp, yp] = meshgrid(-2:0.5:2, -2:0.5:2);
zp = (-n(1)*(xp - plane_point(1)) - n(2)*(yp - plane_point(2))) / n(3) + plane_point(3);
surf(xp, yp, zp,'FaceAlpha', 0.3, 'EdgeColor', 'none', 'FaceColor', 'yellow');
axis equal;
title('Projection of 3D Objects onto Arbitrary Plane');
If the plane is defined by an equation in the standard form: Ax+By+Cz+D=0, extract the normal vector from coefficients and follow the same math.
I hope this answers your query!

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by