Can I create light source that doesnt affect some certain surfaces all in the same axis?

4 次查看(过去 30 天)
I'm doing a project where I'm trying to "simulate" the orbit of planets around a star. Thing is, I'm trying to do it in 3d with surf and using light to make it look 3d and just better overall.
It's all working fine, my only problem is that, when I create a light in the center to simulate the light emitted by the star, the star gets dim, cause, realistically, no lighting is shining on its surface, so it make sense.
I was wondering if there is a way to make lights only affect certain objects or if there is a way to make a sphere emit light?
This is not my exact code, but it's an example:
[X,Y,Z] = sphere();
X2 = X + 4;
Y2 = Y + 4;
Z2 = Z;
max_limit = 5;
surf(X,Y,Z, 'FaceColor', "y" , 'EdgeAlpha', 0)
material dull;
hold on;
surf(X2,Y2,Z2, 'FaceColor', "b" , 'EdgeAlpha', 0)
material dull;
daspect([1 1 1]);
light("Position", [0 0 0], "Style", "local", "Color", "w");
lighting gouraud;
xlim([-max_limit max_limit]);
ylim([-max_limit max_limit]);
zlim([-max_limit max_limit]);
xlabel("X");
ylabel("Y");
zlabel("Z");
title("Plot of the planet");
The image I attached should be the result, as the title says, I'm wondering if there is a way to make the Sphere in the center look lit?
Is there any library maybe?

回答(1 个)

Poorna
Poorna 2024-4-4
Hi Francisco,
I see you want to simulate a planet orbiting a star using MATLAB graphics and want to make the plot realistic in 3D by simulating a star emitting light and the planets reflecting the light.
I also understand that you want to be able to select objects that are affected by the light. You can simulate the required behaviour by multiple axes.
I see you want the star to not get affected by light source that is positioned at the center of it. To achieve this, you can stack two axes on top of another. You can place the light source and planet in one axis and the star in another axis. Because light sources only affect the objects in it's axis, the star which is in the other axis will not be affected. You can modify the above code something like below:
[X,Y,Z] = sphere();
X2 = X + 4;
Y2 = Y + 4;
Z2 = Z;
max_limit = 5;
figure; %initialize a figure
surf(X,Y,Z, 'FaceColor', "y" , 'EdgeAlpha', 0);
material dull;
daspect([1 1 1]);
xlim([-5 5]);
ylim([-5 5]);
zlim([-5 5]);
axis_star = gca;
%create another axis and place it in the same position as the other axis
axis_planet = axes('position', get(axis_star, 'position'));
surf(X2,Y2,Z2, 'FaceColor', "b" , 'EdgeAlpha', 0)
material dull;
daspect([1 1 1]);
light("Position", [0 0 0], "Style", "local", "Color", "w");
lighting gouraud;
xlim([-5 5]);
ylim([-5 5]);
zlim([-5 5]);
xlabel("X");
ylabel("Y");
zlabel("Z");
title("Plot of the planet");
%make the top axis transparent
set(axis_planet, 'color', 'none');
Hope this Helps!

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by