• No results found

LIGHTING AND MATERIAL

(iii) Grayscale Image

5.9 LIGHTING AND MATERIAL

5.9.1 Light

Light can be used to create a light source. Light creates a light object in the current axes.

This light created affects only patch and surface objects.

Lighting source is a bulb and the material is a metallic piece. The lighting depends both on the source and the material.

The syntax for light is,

light (‘Property1’,value1, ‘Property2’,value2…) handle = light (…)

It is possible to create a light object having specified values for the properties mentioned.

A handle to the light object can also be created using the command, handle = light (…)

For example,

MATLAB Program Output

[u,v] = meshgrid((0:0.1:1)*pi,(0:0.1:2)*pi);

a=10+10*cos(v).*sin(u);

b=10*sqrt(3)+10*sin(v).*sin(u);

c=0+10*cos(u);

h= surf(a,b,c);

xlabel(‘X-Axis’) ylabel(‘Y-Axis’)

set(h,’FaceLighting’,’flat’,’FaceColor’,’interp’,’AmbientStrength’,0.7) light(‘Position’,[1 1 1],’Style’,’infinite’);

[u,v] = meshgrid((0:0.1:1)*pi,(0:0.1:2)*pi);

a=10+10*cos(v).*sin(u);

b=10*sqrt(3)+10*sin(v).*sin(u);

c=0+10*cos(u);

h= surf(a,b,c);

sphere

light(‘color’,’g’,’style’,’local’,’position’,[0 0 10])

The variation in light angle and material Output

>> sphere

>> camlight

>> lighting phong

>> sphere

>> camlight

>> lighting phong

>> lightangle (0, 50)

sphere camlight lighting phong lightangle (0, 50) material metal

sphere camlight lighting phong lightangle (0, 50) material shiny

sphere camlight lighting phong lightangle (0, 50) material dull

5.9.2 Material

The choice of the material in MATLAB decides the reflectance properties of the surfaces and patches. The material command sets the lighting characteristics of surfaces and patch.

objects. The material command sets the AmbientStrength, DiffuseStrength, SpecularStrength, SpecularExponent, and Specular Color Reflectance properties of all the

Besides the choice of shiny dull and metal we can also choose a material specifically designed by us. The syntax for this is,

1. material ([ka kd ks]) 2. material ([ka kd ks n]) 3. material ([ka kd ks n sc])

Here ka stands for ambient, diffuse and specular strength of the object. The choice of default gives us default material. n stands for the specular exponent and sc stands for the specular color reflectance of the object. The material default option gives us the default material.

In MATLAB material is used for determining the reflectance properties of surfaces and patches.

For example, here a sphere has been created along with a light source using the MATLAB program given below. The material of the sphere is now changed to find the effect of the light on the object. sphere is changed using the various options available for material. Before we know the various options available for material in MATLAB we must know the following terms:

Specular reflection—Specular reflection is mirror-like reflection of light from a surface

or object. In specular reflection light from a single incoming direction is reflected back in a single outgoing direction. The angle of incidence is equal to the angle of reflection. The incident, reflected and normal directions are coplanar. Ks is the coefficient of specular reflection. The specular color reflectance property of the patch or the surface controls the color.

material ([0 0.2 0.2]) material ([0.5 0.2 0.2]) material ([1 0.2 0.2])

As Ks is increased from 0 to 1 the sphere looks different.

Ambient reflection—The intensity of ambient light is uniform at every point. The ambient reflection coefficient Ka, 0 £ Ka £ 1, determines the reflected fraction of ambient light. La is the ambient component of light source and the ambient intensity is Ia = Ka × La. In the example given below Ka is increased gradually for 0 to 1.

material ([0.2 0 0.2]) material ([0.2 0.5 0.2]) material ([0.2 1 0.2])

Diffuse reflection—Diffuse reflection is the reflection of light from a surface such that an incident ray is reflected at many angles instead of a single angle as in the case of specular reflection. Many surfaces are known to reflect light diffusely. Several surfaces also show a mixture of diffuse and specular reflection. Kd is the coefficient of diffuse reflection. In the example given below Kd is increased gradually from 0 to 1.

material ([0.2 0.2 0]) material ([0.2 0.2 0.5]) material ([0.2 0.2 1])

The various options for materials are listed below.

Material Property Command Output

material shiny

Sets the reflectance properties of the material so that it has a high specular reflectance relative to the diffuse and ambient light. The colour of the specular light depends only on the color of the light source.

material shiny

material dull

Sets the reflectance properties of the material so that the object reflects more diffuse light and has no specular highlights, but the color of the reflected light depend only on the light source.

Sets the ambient, diffuse and specular refection coefficient of the object. material ([0.7 0.2

Sets the ambient, diffuse and specular reflection coefficient and specular exponent of the objects.

Sets the ambient, diffuse, specular reflection coefficeint and specular exponent and specular color reflectance of the objects.

Sets the ambient/diffuse/ specular reflectance stregth, specular exponent, and specular color reflectance of the objects to their defaults values.

This choice sets the reflectance properties of the object such that the object has a high specular reflectance relative to the diffuse and ambient light. The color of the specular light

light(‘Position’,[0 0 20],’Style’,’infinite’);

material shiny

material dull

The option dull for material sets the reflectance properties so that the object reflects more diffuse light and has no specular highlights, but the color of the reflected light depends only

The material metal option sets the reflectance properties so that the object has a very high specular reflectance, very low ambient and diffuse reflectance, and the color of the reflected

The material([ka kd ks n]) option sets the ambient/diffuse/specular strength and specular exponent of the objects.

b1=10*sin(v).*sin(u);

The material([ka kd ks n sc]) option sets the ambient/diffuse/specular strength, specular exponent, and specular color reflectance of the objects.

It is thus possible to set the specular, diffuse and ambient reflection coefficient of a surface or patch and thus affect the way they look when light source is applied.

5.10 VIEW

MATLAB allows us to set the viewpoint to control the orientations of the graphics displayed in the axis. One can set the orientation of the graphics using the view command.

The view command specifies the viewpoint by fixing the azimuth and the elevation with respect to the origin. Azimuth is the polar angle in the x-y plane. A vector from the origin to the point of interest is projected perpendicularly onto a reference plane. The angle between the projected vector and the reference vector on the reference plane is called the azimuth. The counter-clockwise direction of rotation is considered the positive azimuth angle. Elevation is the angle above or below the x-y plane. The angle of elevation is the angle above the horizontal that an observer must look to see the object. Elevation angles for objects above the horizon can range from 0° (objects on the horizon) up to 90° (objects at the zenith). The counter-clockwise direction of rotation in the z-x plane is considered the positive elevation angle. The figure below explains the azimuth and elevation angles.

Azimuth and elevation angles The various syntaxes available for view are:

Setting the viewpoint using view

Output Comments

>> surf (peaks)

>> view (2)

view (2) sets the default 2-dimensional view having az = 0, el = 90.

>> view (3) view (3) sets the default 3-dimensional view having az = – 37.5, el = 30.

>> view (10,50) or

>> view ([10,50])

Both view (10, 50) or view (([10, 50]) give the same result.

The command [az, el] = view returns the current azimuth and elevation. For example,

Setting the viewpoint using view Output Setting the viewpoint using view Output

>> sphere

>> view (0,90)

view (0,0)

>> sphere

>> view (0,60)

>> sphere

>> view (90,90)

>> sphere

>> view (0,10)

>> view (10,50)

>> sphere >> view (50,10)

>> sphere

>> view (0,–10)

>> sphere

>> view (0,–60)

>> sphere

>> view (0,–90)

>> sphere

>> view (90,0)

The command [az,el] = view returns the current azimuth and elevation. For example,

>> [az,el]=view az =

–37.5000 el = 30

T = view returns the current 4-by-4 transformation matrix.

>>surf (peaks) view (2)

>> T=view T =

In the example given below the viewpoint has been set at various combinations of azimuth and elevation angles.

>> sphere

>> view(10,60)

>> sphere

>> view(60,60)

MATLAB Code View View angle

A 2-dimensional scatter plot can be plotted using the scatter function. The various syntaxes available for scatter plot are:

Command Output Explanation

x = linspace (0,5*pi,100);

y = sin (x)+cos (x);

subplot (2,2,1) scatter (X,Y)

Related documents