主要内容

camlight

在相机坐标系中创建或移动光源对象

    说明

    camlight 创建从相机位置看照向右上方的光源。

    示例

    camlight(position) 在指定位置创建一个光源。例如,camlight("left") 创建从相机位置看照向左上方的光源。

    示例

    camlight(az,el) 在指定方位角 az 和仰角 el(相对于相机位置)处创建光源。相机目标是旋转的中心。

    示例

    camlight(___,style) 创建具有指定光源样式的光源。

    示例

    camlight(lt,___) 使用指定的光源,而不是创建新光源。将 lt 指定为第一个参量,后跟上述语法中的任何输入参量组合。

    示例

    camlight(ax,___) 将在由 ax 指定的坐标区中而不是在当前坐标区 (gca) 中创建光源对象。将坐标区指定为上述任一语法中的第一个参量。

    示例

    cl = camlight(___) 返回 Light 对象。创建光源后,使用 cl 来移动光源或修改光源的属性。有关属性列表,请参阅 Light 属性

    示例

    示例

    全部折叠

    创建一个球体,并用光源照射它。将光源置于相机位置的右上方。

    sphere
    axis equal
    camlight

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

    添加另一个相机位置左上方的光源。

    camlight("left")

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

    创建一个球体,并用光源照射它。将光源置于相机位置的左上方。

    sphere
    axis equal
    cl = camlight("left");

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

    将光源移到相机位置的正前方。

    camlight(cl,0,0);

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

    删除光源。

    delete(cl)

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

    自 R2019b 开始提供

    您可以使用 tiledlayoutnexttile 函数显示分块图。使用 tiledlayout 函数以创建 1×2 分块图布局。使用 nexttile 函数创建 Axes 对象 ax1ax2。通过将每个 Axes 对象指定为 surfcamlight 的第一个参量,在每个绘图中创建一个曲面和对应的光源。

    在左侧坐标区中,创建一个曲面,并将光源放在无限远处直接照射该曲面。在右侧坐标区中,创建一个曲面,并将光源放在无限远处从曲面的右侧和上方照射。

    tiledlayout(1,2)
     
    % Left surface
    ax1 = nexttile;
    surf(ax1,peaks,EdgeColor="none")
    lt1 = camlight(ax1,"headlight","infinite");
    title("Infinite light shining at surface")
     
    % Right surface
    ax2 = nexttile;
    surf(ax2,peaks,EdgeColor="none")
    lt2 = camlight(ax2,"right","infinite");
    title("Infinite light shining from the right of surface")

    Figure contains 2 axes objects. Axes object 1 with title Infinite light shining at surface contains an object of type surface. Axes object 2 with title Infinite light shining from the right of surface contains an object of type surface.

    输入参数

    全部折叠

    光源的位置,指定为以下值之一:

    • "right" - 将光源置于相机位置的右上方

    • "left" - 将光源置于相机位置的左上方。

    • "headlight" - 将光源置于相机位置。

    光源的位置取决于 style 参量的值。

    光源位置的方位角,指定为以度为单位的标量值。

    光源位置的仰角,指定为以度为单位的标量值。

    光源类型,指定为下列值之一:

    • "local" - 光源是从光源位置指定的位置向四面八方辐射的点光源。

    • "infinite" - 光源放置在无限远处,以平行光线沿光线位置指定的方向照射。

    要移动的光源,指定为 Light 对象。

    目标坐标区,指定为 Axes 对象。如果未指定坐标区,则 camlight 会在当前坐标区中创建 Light 对象。

    提示

    • camlight 函数设置 Light 对象的 PositionStyle 属性。光源不会随相机动而移动。要使光源保持在固定位置(相对于相机),请在移动相机时调用 camlight

    版本历史记录

    在 R2006a 之前推出

    另请参阅

    函数

    属性