表面プロパティの変更
この例では、MATLAB® で表面プロットのプロパティを取得し、プロパティ値を変更してプロットをカスタマイズする方法を示します。
surface オブジェクト
MATLAB で surface オブジェクトを作成する方法はいくつかあります。1 つは、surf
を使用する方法です。
[X,Y,Z] = peaks(50); figure surf(X,Y,Z)
他のすべてのグラフィックス オブジェクトと同様に、surface には表示と変更が可能なプロパティがあります。こうしたプロパティには既定値があります。surface オブジェクト s
を表示すると、EdgeColor
、LineStyle
、FaceColor
、FaceLighting
など、最もよく使用される表面プロパティが示されます。
s = surf(X,Y,Z)
s = Surface with properties: EdgeColor: [0 0 0] LineStyle: '-' FaceColor: 'flat' FaceLighting: 'flat' FaceAlpha: 1 XData: [50x50 double] YData: [50x50 double] ZData: [50x50 double] CData: [50x50 double] Use GET to show all properties
個々の表面プロパティの取得
個々のプロパティにアクセスするには、ドット表記構文 object.PropertyName
を使用します。たとえば、表面の FaceColor
プロパティを返します。
s.FaceColor
ans = 'flat'
よく使用する表面プロパティの変更
表面プロパティを変更するために、いくつかの関数が使用できます。たとえば、関数 shading
を使用して表面のシェーディングを制御します。
shading interp % interpolate the colormap across the surface face
関数 lighting
を使用して表面のライティング特性を調整します。lighting
が効果をもつには、light オブジェクトを作成して表面にライトを当てなければなりません。
light % create a light lighting gouraud % preferred method for lighting curved surfaces
表面の反射率プロパティを変更するには、関数 material
を使用します。
material dull % set material to be dull, no specular highlights
現在の座標軸にある全オブジェクトの透明度を設定するには、関数 alpha
を使用します。この関数により、透明度を 1 ~ 0 の任意の値に設定します。1 は完全な不透明を表し、0 は完全な透明を表します。
alpha(0.8) % set transparency to 0.8
その他の表面プロパティの変更
表面の外観をカスタマイズするには、ドット表記を使用してプロパティ値を変更します。
CData
は、表面の頂点の色を定義します。FaceColor
プロパティは、頂点の色から表面の面の色を決定する方法を示します。
s.CData = hypot(X,Y); % set color data
s.FaceColor = 'interp'; % interpolate to get face colors
AlphaData
は、表面の各頂点の透明度を定義します。FaceAlpha
プロパティは、表面の透明度を頂点の透明度から決定する方法を示します。
s.AlphaData = gradient(Z); % set vertex transparencies s.FaceAlpha = 'interp'; % interpolate to get face transparencies
すべての表面プロパティの取得
MATLAB のグラフィックス オブジェクトには多数のプロパティがあります。表面のすべてのプロパティを表示するには、get
コマンドを使用します。
get(s)
AlignVertexCenters: off AlphaData: [50x50 double] AlphaDataMapping: 'scaled' AmbientStrength: 0.3000 Annotation: [1x1 matlab.graphics.eventdata.Annotation] BackFaceLighting: 'reverselit' BeingDeleted: off BusyAction: 'queue' ButtonDownFcn: '' CData: [50x50 double] CDataMapping: 'scaled' CDataMode: 'manual' CDataSource: '' Children: [0x0 GraphicsPlaceholder] Clipping: on ContextMenu: [0x0 GraphicsPlaceholder] CreateFcn: '' DataTipTemplate: [1x1 matlab.graphics.datatip.DataTipTemplate] DeleteFcn: '' DiffuseStrength: 0.8000 DisplayName: '' EdgeAlpha: 1 EdgeColor: 'none' EdgeLighting: 'none' FaceAlpha: 'interp' FaceColor: 'interp' FaceLighting: 'gouraud' FaceNormals: [49x49x3 double] FaceNormalsMode: 'auto' HandleVisibility: 'on' HitTest: on Interruptible: on LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerEdgeColor: 'auto' MarkerFaceColor: 'none' MarkerSize: 6 MeshStyle: 'both' Parent: [1x1 Axes] PickableParts: 'visible' Selected: off SelectionHighlight: on SpecularColorReflectance: 1 SpecularExponent: 10 SpecularStrength: 0 Tag: '' Type: 'surface' UserData: [] VertexNormals: [50x50x3 double] VertexNormalsMode: 'auto' Visible: on XData: [50x50 double] XDataMode: 'manual' XDataSource: '' YData: [50x50 double] YDataMode: 'manual' YDataSource: '' ZData: [50x50 double] ZDataSource: ''