View a 2-d projection of a 3D object

14 Ansichten (letzte 30 Tage)
Lovett
Lovett am 11 Mai 2023
Kommentiert: Lovett am 11 Mai 2023
I tried usind the matlab function "view" but it doesn't give a projected face

Antworten (1)

Shaik
Shaik am 11 Mai 2023
Hi Lovett,
The view function in MATLAB sets the camera viewpoint for the current figure, but it does not render the 3D object in perspective. To render a 3D object in perspective so that it appears to have depth in a 2D image, you can use the camproj and camva functions to adjust the camera projection and field of view (FOV). Here's an example:
% Generate some random data
x = randn(100,1);
y = randn(100,1);
z = randn(100,1);
% Plot the data as a 3D scatter plot
figure;
scatter3(x,y,z);
% Adjust the view to a projected 2D view from above
camproj('perspective'); % set perspective projection
camup([0 1 0]); % set camera up direction
campos([0 0 max(z)]); % set camera position
camva(30); % set camera view angle
  1 Kommentar
Lovett
Lovett am 11 Mai 2023
Thank you so much.
How do I use this to project each face of the solid generated by this code.
% Clear all previous commands
clear all
close all
clc
figure(2)
% Variables you can change
Sizex = 1; %average length of RVE
Sizey = 1;
Sizez = 1;
Def = 60; %definition
% Variables you shouldn´t change
SFactx = (Sizex/2)/pi; %size factor of RVE
SFacty = (Sizey/2)/pi;
SFactz = (Sizez/2)/pi;
A = SFactx*pi; %lowest and max coordinates of meshgrid
B = SFacty*pi;
C = SFactz*pi;
Dx = A/Def;%definition factor
Dy = B/Def;
Dz = C/Def;
% Generation of gyroids
[X,Y,Z] = meshgrid(-A:Dx:A, -B:Dy:B, -C:Dz:C); %creates mesh grid
% Gyroid equation
OBJ =(cos(X/SFactx).* sin(Y/SFacty) + cos(Y/SFacty).* sin(Z/SFactz)...
+ cos(Z/SFactz).* sin(X/SFactx)+(0));
T = 0.5;
OBJ =(OBJ-T);
% Isosurface and isocap
[F1,V1] = isosurface(X,Y,Z,OBJ,0);
[F2,V2] = isocaps(X,Y,Z,OBJ,0,'below');
%Combines isosurface and isocaps into one
F3 = [F1;F2+length(V1(:,1))];
V3 = [V1;V2];
% Visualization
P = patch('Vertices',V3,'Faces',F3,'FaceColor', ...
'cyan','EdgeColor','none');
view(3)
camlight
%Visualization
axis equal
stlwrite('G1-T05.stl',V3,F3)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Lighting, Transparency, and Shading 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