Main Content

복잡한 3차원 객체 표시

이 예제에서는 복잡한 3차원 객체를 만들고 표시하며 이 객체의 모양을 제어하는 방법을 보여줍니다.

객체의 기하(Geometry) 가져오기

이 예제에서는 뉴얼 티포트(Newell teapot)라는 그래픽스 객체를 사용합니다. 티포트의 꼭짓점, 면, 색 인덱스 데이터는 teapotData 함수에 의해 계산됩니다. 티포트는 복잡한 기하학 모양이므로, 많은 수의 꼭짓점(4608개)과 면(3872개)이 이 함수에서 반환됩니다.

[verts, faces, cindex] = teapotGeometry;

티포트 patch 객체 생성

patch 명령을 사용하여 기하학 데이터를 이용해서 티포트를 그립니다. patch 명령은 patch 객체를 생성합니다.

figure
p = patch('Faces',faces,'Vertices',verts,'FaceVertexCData',cindex,'FaceColor','interp')

Figure contains an axes object. The axes object contains an object of type patch.

p = 
  Patch with properties:

    FaceColor: 'interp'
    FaceAlpha: 1
    EdgeColor: [0 0 0]
    LineStyle: '-'
        Faces: [3872x4 double]
     Vertices: [4608x3 double]

  Use GET to show all properties

view 명령을 사용하여 객체의 방향을 변경합니다.

view(-151,30)     % change the orientation
axis equal off    % make the axes equal and invisible

투명도 조정

patch 객체의 FaceAlpha 속성을 사용하여 객체를 투명하게 만듭니다.

p.FaceAlpha = 0.3;   % make the object semi-transparent

FaceColor 속성이 'none'으로 설정되어 있으면 객체가 와이어프레임 다이어그램으로 나타납니다.

p.FaceColor = 'none';    % turn off the colors

컬러맵 변경

colormap 함수를 사용하여 객체의 색을 변경합니다.

p.FaceAlpha = 1;           % remove the transparency
p.FaceColor = 'interp';    % set the face colors to be interpolated
p.LineStyle = 'none';      % remove the lines
colormap(copper)           % change the colormap

객체에 조명 비추기

조명을 추가하여 객체를 좀 더 사실적으로 표현할 수 있습니다.

l = light('Position',[-0.4 0.2 0.9],'Style','infinite')
l = 
  Light with properties:

       Color: [1 1 1]
       Style: 'infinite'
    Position: [-0.4000 0.2000 0.9000]
     Visible: on

  Use GET to show all properties

lighting gouraud

patch 객체의 다음 속성은 조명의 강도와 객체의 반사 속성에 영향을 미칩니다.

  • AmbientStrength - 주변광의 강도 제어

  • DiffuseStrength - 확산광의 강도 제어

  • SpecularStrength - 반사광의 강도 제어

  • SpecularExponent - 반사광의 거칠기 제어

  • SpecularColorReflectance - 반사된 색의 계산 방법 제어.

이러한 속성을 개별적으로 설정할 수 있습니다. 이러한 속성을 금속, 반짝이는 물질 또는 윤기 없는 물질의 모양에 근접한 미리 지정한 값 세트로 설정하려면 material 명령을 사용하십시오.

material shiny

조명의 Position 속성을 사용하여 조명 위치를 조정합니다. 위치는 x, y, z 좌표로 표시됩니다.

l.Position = [-0.1 0.6 0.8]

l = 
  Light with properties:

       Color: [1 1 1]
       Style: 'infinite'
    Position: [-0.1000 0.6000 0.8000]
     Visible: on

  Use GET to show all properties