Skip to content

Commit

Permalink
meshes3d: add demos for intersectLineMesh3d and intersectPlaneMesh
Browse files Browse the repository at this point in the history
  • Loading branch information
dlegland committed Aug 2, 2021
1 parent d6bb200 commit 4f2b721
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 0 deletions.
56 changes: 56 additions & 0 deletions demos/meshes3d/demoIntersectLineMesh3d.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
% Demonstration of the intersectLineMesh3d function.
%
% output = demoIntersectLineMesh3d(input)
%
% Example
% demoIntersectLineMesh3d
%
% See also
%

% ------
% Author: David Legland
% e-mail: [email protected]
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
% Created: 2021-08-02, using Matlab 9.10.0.1684407 (R2021a) Update 3
% Copyright 2021 INRAE.


%% Input mesh

% create the mesh
[v, f] = createOctahedron;
v = v * 10;

% draw the mesh
figure; hold on; axis equal; view(3);
axis([-10 10 -10 10 -10 10]);
drawMesh(v, f, 'g');


%% Input lines
% create a collection of parallel lines

% line direction is mostly horizontal
vl = [3 2 1];

% choose several origins for lines
ly = -8:4:8;
lz = -8:4:8;
[y0, z0] = meshgrid(ly, lz);
x0 = zeros(size(y0));

% create the lines
lines = [x0(:) y0(:) z0(:) repmat(vl, numel(y0), 1)];

% draw the lines
drawLine3d(lines, 'b');


%% Compute intersections

% compute intersections
inters = intersectLineMesh3d(lines, v, f);

% draw intersection points
drawPoint3d(inters, 'ko');
63 changes: 63 additions & 0 deletions demos/meshes3d/demoIntersectPlaneMesh.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
% Demonstration of the intersectPlaneMesh function.
%
% output = demoIntersectPlaneMesh(input)
%
% Example
% demoIntersectPlaneMesh
%
% See also
%

% ------
% Author: David Legland
% e-mail: [email protected]
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
% Created: 2021-08-02, using Matlab 9.10.0.1684407 (R2021a) Update 3
% Copyright 2021 INRAE.


%% Input mesh

% create the mesh
[v, f] = createOctahedron;
v = v * 10;

% draw the mesh
figure; hold on; axis equal; view(3);
axis([-10 10 -10 10 -10 10]);
drawMesh(v, f, 'g');


%% Input planes
% create a collection of parallel planes

% planedirection is mostly horizontal
normal = [2 3 8];

% choose several origins for planes
origins = [zeros(5, 2) (-8:4:8)'];
nPlanes = size(origins, 1);

% create the planes
planes = zeros(nPlanes, 9);
for i = 1:nPlanes
planes(i,:) = createPlane(origins(i,:), normal);
end

% draw the lines
drawPlane3d(planes, 'FaceColor', 'blue', 'FaceAlpha', .4);


%% Compute intersections

% allocate array
polySets = cell(1, nPlanes);

% compute intersections
for i = 1:nPlanes
polys = intersectPlaneMesh(planes(i,:), v, f);
polySets{i} = polys;
end

% draw intersection points
drawPolygon3d(polySets, 'Color', 'magenta', 'LineWidth', 2);
173 changes: 173 additions & 0 deletions demos/meshes3d/html/demoIntersectLineMesh3d.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@

<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!--
This HTML was auto-generated from MATLAB code.
To make changes, update the MATLAB code and republish this document.
--><title>demoIntersectLineMesh3d</title><meta name="generator" content="MATLAB 9.10"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2021-08-02"><meta name="DC.source" content="demoIntersectLineMesh3d.m"><style type="text/css">
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}

html { min-height:100%; margin-bottom:1px; }
html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; }
html body td { vertical-align:top; text-align:left; }

h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; }
h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }
h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; }

a { color:#005fce; text-decoration:none; }
a:hover { color:#005fce; text-decoration:underline; }
a:visited { color:#004aa0; text-decoration:none; }

p { padding:0px; margin:0px 0px 20px; }
img { padding:0px; margin:0px 0px 20px; border:none; }
p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; }

ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; }
ul li { padding:0px; margin:0px 0px 7px 0px; }
ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; }
ul li ol li { list-style:decimal; }
ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; }
ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; }
ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; }
ol li ol li { list-style-type:lower-alpha; }
ol li ul { padding-top:7px; }
ol li ul li { list-style:square; }

.content { font-size:1.2em; line-height:140%; padding: 20px; }

pre, code { font-size:12px; }
tt { font-size: 1.2em; }
pre { margin:0px 0px 20px; }
pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; }
pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; }
pre.error { color:red; }

@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }

span.keyword { color:#0000FF }
span.comment { color:#228B22 }
span.string { color:#A020F0 }
span.untermstring { color:#B20000 }
span.syscmd { color:#B28C00 }
span.typesection { color:#A0522D }

.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; }
.footer p { margin:0px; }
.footer a { color:#878787; }
.footer a:hover { color:#878787; text-decoration:underline; }
.footer a:visited { color:#878787; }

table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; }
table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; }





</style></head><body><div class="content"><h2>Contents</h2><div><ul><li><a href="#2">Input mesh</a></li><li><a href="#3">Input lines</a></li><li><a href="#4">Compute intersections</a></li></ul></div><pre class="codeinput"><span class="comment">% Demonstration of the intersectLineMesh3d function.</span>
<span class="comment">%</span>
<span class="comment">% output = demoIntersectLineMesh3d(input)</span>
<span class="comment">%</span>
<span class="comment">% Example</span>
<span class="comment">% demoIntersectLineMesh3d</span>
<span class="comment">%</span>
<span class="comment">% See also</span>
<span class="comment">%</span>

<span class="comment">% ------</span>
<span class="comment">% Author: David Legland</span>
<span class="comment">% e-mail: [email protected]</span>
<span class="comment">% INRAE - BIA Research Unit - BIBS Platform (Nantes)</span>
<span class="comment">% Created: 2021-08-02, using Matlab 9.10.0.1684407 (R2021a) Update 3</span>
<span class="comment">% Copyright 2021 INRAE.</span>
</pre><h2 id="2">Input mesh</h2><pre class="codeinput"><span class="comment">% create the mesh</span>
[v, f] = createOctahedron;
v = v * 10;

<span class="comment">% draw the mesh</span>
figure; hold <span class="string">on</span>; axis <span class="string">equal</span>; view(3);
axis([-10 10 -10 10 -10 10]);
drawMesh(v, f, <span class="string">'g'</span>);
</pre><img vspace="5" hspace="5" src="demoIntersectLineMesh3d_01.png" alt=""> <h2 id="3">Input lines</h2><p>create a collection of parallel lines</p><pre class="codeinput"><span class="comment">% line direction is mostly horizontal</span>
vl = [3 2 1];

<span class="comment">% choose several origins for lines</span>
ly = -8:4:8;
lz = -8:4:8;
[y0, z0] = meshgrid(ly, lz);
x0 = zeros(size(y0));

<span class="comment">% create the lines</span>
lines = [x0(:) y0(:) z0(:) repmat(vl, numel(y0), 1)];

<span class="comment">% draw the lines</span>
drawLine3d(lines, <span class="string">'b'</span>);
</pre><img vspace="5" hspace="5" src="demoIntersectLineMesh3d_02.png" alt=""> <h2 id="4">Compute intersections</h2><pre class="codeinput"><span class="comment">% compute intersections</span>
inters = intersectLineMesh3d(lines, v, f);

<span class="comment">% draw intersection points</span>
drawPoint3d(inters, <span class="string">'ko'</span>);
</pre><img vspace="5" hspace="5" src="demoIntersectLineMesh3d_03.png" alt=""> <p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB&reg; R2021a</a><br></p></div><!--
##### SOURCE BEGIN #####
% Demonstration of the intersectLineMesh3d function.
%
% output = demoIntersectLineMesh3d(input)
%
% Example
% demoIntersectLineMesh3d
%
% See also
%
% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH
% Author: David Legland
% e-mail: [email protected]
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
% Created: 2021-08-02, using Matlab 9.10.0.1684407 (R2021a) Update 3
% Copyright 2021 INRAE.
%% Input mesh
% create the mesh
[v, f] = createOctahedron;
v = v * 10;
% draw the mesh
figure; hold on; axis equal; view(3);
axis([-10 10 -10 10 -10 10]);
drawMesh(v, f, 'g');
%% Input lines
% create a collection of parallel lines
% line direction is mostly horizontal
vl = [3 2 1];
% choose several origins for lines
ly = -8:4:8;
lz = -8:4:8;
[y0, z0] = meshgrid(ly, lz);
x0 = zeros(size(y0));
% create the lines
lines = [x0(:) y0(:) z0(:) repmat(vl, numel(y0), 1)];
% draw the lines
drawLine3d(lines, 'b');
%% Compute intersections
% compute intersections
inters = intersectLineMesh3d(lines, v, f);
% draw intersection points
drawPoint3d(inters, 'ko');
##### SOURCE END #####
--></body></html>
Binary file added demos/meshes3d/html/demoIntersectLineMesh3d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4f2b721

Please sign in to comment.