Light direction in surfl

조회 수: 4 (최근 30일)
Bobby Fischer
Bobby Fischer 2021년 5월 11일
답변: Walter Roberson 2021년 5월 11일
Hi, I don't understand why it is not centered.
x = -1:.1:1;
y = -1:.1:1;
[X,Y] = meshgrid(x,y);
z = X.^2 + Y.^2;
surfl(x,y,z, [0 0 1])

채택된 답변

Walter Roberson
Walter Roberson 2021년 5월 11일
The bright area is mostly because of the specular lighting that is being introduced.
doc specular says
R = specular(Nx,Ny,Nz,S,V) returns the reflectance of a surface with normal vector components [Nx,Ny,Nz]. S and V specify the direction to the light source and to the viewer, respectively. You can specify these directions as three vectors[x,y,z] or two vectors [Theta Phi (in spherical coordinates).
The specular highlight is strongest when the normal vector is in the direction of (S+V)/2 where S is the source direction, and V is the view direction.
The S that is used is the one you pass in, [0 0 1], but the V that is being used is being calculated by taking view() of the axes. In a new axes that has not had anything drawn in it yet, the default view is [-37.5, 30] . And if you do not have hold on in effect, then the newplot() that is automatically done resets the axes to this view.
You have two main choices here:
  1. clear the axes, view() as appropriate, and do hold on before doing the surfl() so that the specular values are calculated according to your desired view; OR
  2. when you call surfl(), pass in the optional 5th parameter, k with a low value in the 3rd component ks so that the specular lighting is not given much weight.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by