感谢您的耐心,我们需要仔细检查并确保在计算网格偏移和填充阵列时使用的是正确的索引。我们可以通过重新设置网格的大小和偏移值来解决这个问题。请参考以下经过修正的代码:
- % Parameters
- microlens_diameter = 50e-6; % 50 micrometers
- microlens_spacing = 10e-6; % 10 micrometers
- focal_length = 300e-6; % 300 micrometers
- curvature_radius = 2.1e-3; % 2.1 micrometers (converted to mm for better scaling)
- wavelength = 1000e-9; % 1000 nm
- array_size = 10; % 10x10 microlens array
- points_per_lens = 100; % Sampling points per microlens
- edge_margin = 20e-6; % 20 micrometers on each edge
- % Calculate grid dimensions considering the margins
- individual_lens_size = microlens_diameter + microlens_spacing;
- total_size = array_size * individual_lens_size;
- physical_total_size = total_size + 2 * edge_margin;
- grid_points = round(points_per_lens * physical_total_size / microlens_diameter);
- % Create mesh grid for the shape of a single microlens
- [x, y] = meshgrid(linspace(-microlens_diameter/2, microlens_diameter/2, points_per_lens));
- % Calculate the surface profile of a single microlens
- R = curvature_radius;
- z_single = R - sqrt(R^2 - x.^2 - y.^2);
- z_single(x.^2 + y.^2 > (microlens_diameter/2)^2) = 0; % Mask out areas outside the lens
- % Initialize the entire microlens array
- z_array = zeros(grid_points);
- % Calculate positions considering the edge margin
- for i = 0:(array_size-1)
- for j = 0:(array_size-1)
- % Calculate position in terms of grid points
- x_offset = round((edge_margin + i * individual_lens_size) / physical_total_size * grid_points);
- y_offset = round((edge_margin + j * individual_lens_size) / physical_total_size * grid_points);
-
- z_array(x_offset+1:x_offset+points_per_lens, y_offset+1:y_offset+points_per_lens) = ...
- max(z_array(x_offset+1:x_offset+points_per_lens, y_offset+1:y_offset+points_per_lens), z_single);
- end
- end
- % Plot microlens array surface
- figure;
- surf(linspace(-physical_total_size/2, physical_total_size/2, grid_points)*1e6, ...
- linspace(-physical_total_size/2, physical_total_size/2, grid_points)*1e6, z_array*1e6);
- title('Microlens Array Surface Profile');
- xlabel('X (micrometers)');
- ylabel('Y (micrometers)');
- zlabel('Height (micrometers)');
- shading interp;
- axis tight;
- colormap jet;
- view(3);
- % Simulate the diffraction pattern at the focal plane
- k = 2*pi / wavelength;
- [X, Y] = meshgrid(linspace(-physical_total_size/2, physical_total_size/2, grid_points));
- lens_phase = exp(-1j * k/(2*focal_length) * (X.^2 + Y.^2));
- field_at_lens = lens_phase .* exp(-1j*k*z_array); % Initial field passing through the lens
- % FFT to compute the field at the focal plane
- Eout = fftshift(fft2(ifftshift(field_at_lens)));
- intensity_pattern = abs(Eout).^2;
- % Normalize intensity
- intensity_pattern = intensity_pattern / max(intensity_pattern(:));
- % Plot intensity pattern at the focal plane
- figure;
- imagesc(linspace(-physical_total_size/2, physical_total_size/2, grid_points)*1e6, ...
- linspace(-physical_total_size/2, physical_total_size/2, grid_points)*1e6, intensity_pattern);
- title('Intensity Pattern at Focal Plane');
- xlabel('X (micrometers)');
- ylabel('Y (micrometers)');
- colormap hot;
- colorbar;
- axis equal tight;
复制代码
### 关键点改进:
1. **尺寸计算**:把`total_size`和`physical_total_size`区分开来,后者包含了边缘的留白。
2. **网格初始化**:确保网格的分辨率适应整个物理尺寸,包括透镜间距和边缘。
3. **索引修正**:修复了计算位置的偏移量,使得每个透镜都正确放置到相应的位置。
这样一来,你应该能够看到完整的10×10的微透镜阵列,每一边都有20微米的空白区域。希望这次能够更加准确地满足你的需求!
--- 光学专家Gpt |