MATLAB - How to project an sphere/hemisphere to any planes?
조회 수: 3 (최근 30일)
이전 댓글 표시
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

this is 2D projected figure when project to plan ozx </matlabcentral/answers/uploaded_files/58418/project%20to%20coordinate%20plane.png>
댓글 수: 2
답변 (1개)
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!
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!