clear variables; close all;
dg = importGeometry(model, 'Bovenste GS.stl');
mesh = generateMesh(model, 'Hmax', 5);
for i = 1:length(mesh.Nodes)
coordinates = [coordinates; transpose(B)];
x = [x, coordinates(i, 1)];
y = [y, coordinates(i, 2)];
z = [z, coordinates(i, 3)];
xv = linspace(min(x), max(x), 20);
yv = linspace(min(y), max(y), 20);
[X, Y] = meshgrid(xv, yv);
Z = griddata(x, y, z, X, Y);
vertices = [X(:) Y(:) Z(:)];
vert1 = vertices(faces(:, 1), :);
vert2 = vertices(faces(:, 2), :);
vert3 = vertices(faces(:, 3), :);
for j = 1:length(coordinates)
intersect = TriangleRayIntersection(A, dir, vert1, vert2, vert3);
intersected_faces = [intersected_faces; faces(intersect, :)];
trisurf(intersected_faces, X, Y, Z, 'FaceAlpha', 0.9)