function [measuremenImage,xyzImageWorld,laserpixel,...
    borderPixelX,borderPixelY,imageBorderWorld,IntersectionsImageborderGlass,...
    IntersectionsImageborderWater,vectorsImageborderWater,IntersectionsImageborderGround] =...
    raytracingCamera(position,omegaC,phiC,kappaC,c,xmm,ymm,xpixel,ypixel,...
    zMedium1,zMedium2,zGround,n1,n2,n3,IntersectionsLaserGround)

%% interfaces parallel to xy
NormalMedium1 = [0;0;1];
PositionMedium1 = [0;0;zMedium1];
NormalMedium2 = [0;0;1];
PositionMedium2 = [0;0;zMedium2];
NormalGround = [0;0;1];
PositionGround = [0;0;zGround];

%% Camera
% Orientierung
RCamera =  eul2rotm([omegaC,phiC,kappaC],'XYZ');
MCamera = [[RCamera,position];[0,0,0,1]];

% ImageBorder:
numberOfRays = 10;
top_x = linspace(0,xpixel,numberOfRays);
top_y = ones(1,numberOfRays)*ypixel;
right_x = ones(1,numberOfRays)*xpixel;
ritgh_y = linspace(ypixel,0,numberOfRays);
bottom_x = linspace(xpixel,0,numberOfRays);
bottom_y = zeros(1,numberOfRays);
left_x = zeros(1,numberOfRays);
left_y = linspace(0,ypixel,numberOfRays);

borderPixelX = [top_x,right_x,bottom_x,left_x];
borderPixelY = [top_y,ritgh_y,bottom_y,left_y];

borderX = (borderPixelX*xmm/xpixel)-xmm/2;
borderY = ((borderPixelY*ymm/ypixel)-ymm/2);

border = [borderX;borderY;...
    -c*ones(1,4*numberOfRays);...
    ones(1,4*numberOfRays)];


% In world coordinates:
imageBorderWorld =  MCamera*border;
% vectors in world coordinates:
borderVector = position-imageBorderWorld(1:3,:);

% Intersection points and refractions at interfaces:
j = 0;
for i = 1:size(border,2)
    % Uebergang Luft Glas
    [IntersectionsImageborderGlass(:,i),vektorBildrandGlas(:,i)] = refraction(position,borderVector(:,i)./norm(borderVector(:,i)),n1,n2,PositionMedium1,NormalMedium1);
    % Uebergang Glas Wasser
    [IntersectionsImageborderWater(:,i),vectorsImageborderWater(:,i)] = refraction(IntersectionsImageborderGlass(:,i),vektorBildrandGlas(:,i),n2,n3,PositionMedium2,NormalMedium2);
    % Schnittpunkt mit Boden
    [IntersectionsImageborderGround(:,i),~] = line_plane_intersection(vectorsImageborderWater(:,i), IntersectionsImageborderWater(:,i), NormalGround, PositionGround);
    
end


% full image:
% camera coordinates:
[xC,yC] = meshgrid(linspace(-xmm/2,xmm/2,xpixel),linspace(-ymm/2,ymm/2,ypixel));
xyzC = [xC(:)';yC(:)';-c*ones(1,numel(xC));ones(1,numel(xC))];

% In world coordinates:
xyzImageWorld = MCamera*xyzC;

% Vectors in world coordinates :
C = position-xyzImageWorld(1:3,:);

for i = 1:numel(xC)
    % Uebergang Luft Glas
    [IntersectionsImageraysGlass(:,i),vectorsImageraysGlass(:,i)] = refraction(position,C(:,i)./norm(C(:,i)),n1,n2,PositionMedium1,NormalMedium1);
    % Uebergang Glas Wasser
    [IntersectionsImageraysWater(:,i),vectorImageraysWater(:,i)] = refraction(IntersectionsImageraysGlass(:,i),vectorsImageraysGlass(:,i),n2,n3,PositionMedium2,NormalMedium2);
    % Schnittpunkt mit Boden
    [IntersectionsImageraysGround(:,i),~] = line_plane_intersection(vectorImageraysWater(:,i), IntersectionsImageraysWater(:,i), NormalGround, PositionGround);
    
    
    % did image ray hit a laser ?
    distances = sqrt((IntersectionsImageraysGround(1,i)-IntersectionsLaserGround(1,:)).^2 +...
        (IntersectionsImageraysGround(2,i)-IntersectionsLaserGround(2,:)).^2);
    maxDist = 1;    % [pixel]
    if min(distances) < maxDist
        laserpixel(i) = maxDist-min(distances);
    else
        laserpixel(i) = 0;
    end
end

laserimage = reshape(laserpixel,ypixel,xpixel);
measuremenImage = uint8(zeros(ypixel,xpixel,3));
measuremenImage(:,:,2) = uint8(laserimage./maxDist*255);

end

