Contenuto principale

apply

R2026b

Apply tolerance perturbation to optical system

Since R2026b

    Description

    Add-On Required: This feature requires the Optical Design and Simulation Library for Image Processing Toolbox add-on.

    newopsys = apply(tol,opsys) applies a random perturbation within the range of the tolerance, tol, to the target indices specified in tol of the optical system opsys and returns the perturbed system along with the index of the modified element.

    example

    newopsys = apply(tol,opsys,ToleranceValue=perturbValue) specifies the value of the perturbation.

    Examples

    collapse all

    Import an optical system into the workspace.

    opsys = zmximport("PhotographicLens.zmx");

    Define a custom tolerance. The custom tolerance function modifyGap is defined at the end of this example.

    tol = optics.tolerance.CustomTolerance(@modifyGap,[-0.1 0.1])
    tol = 
      CustomTolerance with properties:
    
           TargetProperty: "Custom"
        ToleranceFunction: @modifyGap
            CustomFcnArgs: {1×0 cell}
              TargetIndex: [1×0 double]
           ToleranceRange: [-0.1000 0.1000]
            ToleranceType: "Absolute"
    
    

    Apply the tolerance to the optical system.

    newopsys = apply(tol,opsys);

    Custom Function

    The modifyGap function computes how much to adjust the gap after a specific component and updates the component position. The function gets the current gap after a given component, increases or decreases it according to the perturbation value, and then updates the position of the component to reflect the new gap value.

    function [opsys,requiredGap] = modifyGap(opsys,gapValue)
        compIndex = 2;
        if length(opsys.Components) <= compIndex
            error("Invalid component index")
        end
        currentGap = distanceAfter(opsys,compIndex);
        requiredGap = currentGap-gapValue;
        opsys.Components(compIndex).Position(3) = opsys.Components(compIndex).Position(3)+requiredGap;
    end

    Input Arguments

    collapse all

    Optical system to which to apply perturbation, specified as an opticalSystem object. The function operates on a copy, and does not modify the original optical system.

    Perturbation magnitude, specified as a numeric scalar. The value must be within the tolerance range defined for the tolerance object. If the tolerance object has a percentage tolerance range, this function interprets the perturbation magnitude as a percentage. If the tolerance object has an absolute tolerance range, this function interprets the perturbation magnitude as an absolute value.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Output Arguments

    collapse all

    Perturbed optical system, returned as an opticalSystem object with the specified perturbation applied.

    Version History

    Introduced in R2026b