Mercurial > forge
changeset 11145:08a4f1d5f4b6 octave-forge
geometry: porting geom3d
author | jpicarbajal |
---|---|
date | Mon, 22 Oct 2012 17:18:34 +0000 |
parents | 301055b21910 |
children | e58e22d19159 |
files | main/geometry/NEWS main/geometry/devel/geom3d/createScaling3d.m main/geometry/devel/geom3d/drawCube.m main/geometry/devel/meshes3d/createCube.m main/geometry/inst/geom3d/createScaling3d.m main/geometry/inst/geom3d/drawCube.m main/geometry/inst/meshes3d/createCube.m |
diffstat | 7 files changed, 321 insertions(+), 302 deletions(-) [+] |
line wrap: on
line diff
--- a/main/geometry/NEWS Mon Oct 22 16:58:48 2012 +0000 +++ b/main/geometry/NEWS Mon Oct 22 17:18:34 2012 +0000 @@ -1,5 +1,14 @@ Summary of important user-visible changes for releases of the geometry package =============================================================================== +geometry-1.7.0 Release Date: 2012-XX-XX Release Manager: Juan Pablo Carbajal +=============================================================================== + +** Added Functions + + box3dVolume cart2cyl circle3dPoint cyl2cart + drawCircle3d drawPoint3d + +=============================================================================== geometry-1.6.0 Release Date: 2012-10-12 Release Manager: Juan Pablo Carbajal =============================================================================== ** geometry doesn't autoloads anymore @@ -16,8 +25,7 @@ polygonArea3d transformPoint3d drawBox3d drawEdge3d drawMesh createCubeOctahedron boundingBox3d cart2sph2 circle3dOrigin circle3dPosition drawCircleArc3d drawPolygon3d drawSphericalEdge - drawSphericalPolygon intersectPlaneSphere sph2cart2d box3dVolume - cart2cyl circle3dPoint cyl2cart + drawSphericalPolygon intersectPlaneSphere sph2cart2d ** Updated functions distancePoints
--- a/main/geometry/devel/geom3d/createScaling3d.m Mon Oct 22 16:58:48 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -## Copyright (C) 2004-2011 David Legland <david.legland@grignon.inra.fr> -## Copyright (C) 2004-2011 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) -## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -## All rights reserved. -## -## Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are met: -## -## 1 Redistributions of source code must retain the above copyright notice, -## this list of conditions and the following disclaimer. -## 2 Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in the -## documentation and/or other materials provided with the distribution. -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' -## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR -## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -function trans = createScaling3d(varargin) -#CREATESCALING3D Create the 4x4 matrix of a 3D scaling -# -# TRANS = createScaling3d(S); -# returns the scaling transform corresponding to a scaling factor S in -# each direction. S can be a scalar, or a 1x3 vector containing the -# scaling factor in each direction. -# -# TRANS = createScaling3d(SX, SY, SZ); -# returns the scaling transform corresponding to a different scaling -# factor in each direction. -# -# The returned matrix has the form : -# [SX 0 0 0] -# [ 0 SY 0 0] -# [ 0 0 SZ 0] -# [ 0 0 0 0] -# -# See also: -# transforms3d, transformPoint3d, transformVector3d, createTranslation3d, -# createRotationOx, createRotationOy, createRotationOz -# -# --------- -# author : David Legland -# INRA - TPV URPOI - BIA IMASTE -# created the 20/04/2006. -# - -# HISTORY -# 25/11/2008 rename from scale3d to scaling3d -# 30/04/2009 rename to createScaling3d - - -# process input parameters -if isempty(varargin) - # assert uniform scaling in each direction - sx = 1; - sy = 1; - sz = 1; -elseif length(varargin)==1 - # only one argument - var = varargin{1}; - if length(var)==1 - # same scaling factor in each direction - sx = var; - sy = var; - sz = var; - elseif length(var)==3 - # scaling is a vector, giving different scaling in each direction - sx = var(1); - sy = var(2); - sz = var(3); - else - error('wrong size for first parameter of "createScaling3d"'); - end -elseif length(varargin)==3 - # 3 arguments, giving scaling in each direction - sx = varargin{1}; - sy = varargin{2}; - sz = varargin{3}; -else - error('wrong number of arguments for "createScaling3d"'); -end - -# create the scaling matrix -trans = [sx 0 0 0;0 sy 0 0;0 0 sz 0;0 0 0 1]; -
--- a/main/geometry/devel/geom3d/drawCube.m Mon Oct 22 16:58:48 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -## Copyright (C) 2004-2011 David Legland <david.legland@grignon.inra.fr> -## Copyright (C) 2004-2011 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) -## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -## All rights reserved. -## -## Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are met: -## -## 1 Redistributions of source code must retain the above copyright notice, -## this list of conditions and the following disclaimer. -## 2 Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in the -## documentation and/or other materials provided with the distribution. -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' -## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR -## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -function varargout = drawCube(cube, varargin) -#DRAWCUBE Draw a 3D centered cube, eventually rotated -# -# drawCube(CUBE) -# Displays a 3D cube on current axis. CUBE is given by: -# [XC YC ZC SIDE THETA PHI PSI] -# where (XC, YC, ZC) is the CUBE center, SIDE is the length of the cube -# main sides, and THETA PHI PSI are angles representing the cube -# orientation, in degrees. THETA is the colatitude of the cube, between 0 -# and 90 degrees, PHI is the longitude, and PSI is the rotation angle -# around the axis of the normal. -# -# CUBE can be axis aligned, in this case it should only contain center -# and side information: -# CUBE = [XC YC ZC SIDE] -# -# The function drawCuboid is closely related, but uses a different angle -# convention, and allows for different sizes along directions. -# -# Example -# # Draw a cube with small rotations -# figure; hold on; -# drawCube([10 20 30 50 10 20 30], 'FaceColor', 'g'); -# axis equal; -# view(3); -# -# See also -# meshes3d, polyhedra, createCube, drawCuboid -# -# ------ -# Author: David Legland -# e-mail: david.legland@grignon.inra.fr -# Created: 2011-06-29, using Matlab 7.9.0.529 (R2009b) -# Copyright 2011 INRA - Cepia Software Platform. - - -# default values -theta = 0; -phi = 0; -psi = 0; - -## Parses the input -if nargin == 0 - # no input: assumes cube with default shape - xc = 0; yc = 0; zc = 0; - a = 1; - -else - # one argument: parses elements - xc = cube(:,1); - yc = cube(:,2); - zc = cube(:,3); - a = cube(:,4); - - # parses orientation if present - k = pi / 180; - if size(cube, 2) >= 6 - theta = cube(:,5) * k; - phi = cube(:,6) * k; - end - if size(cube, 2) >= 7 - psi = cube(:,7) * k; - end -end - - -## Compute cube coordinates - -# create unit centered cube -[v f] = createCube; -v = bsxfun(@minus, v, mean(v, 1)); - -# convert unit basis to cube basis -sca = createScaling3d(a); -rot1 = createRotationOz(psi); -rot2 = createRotationOy(theta); -rot3 = createRotationOz(phi); -tra = createTranslation3d([xc yc zc]); - -# concatenate transforms -trans = tra * rot3 * rot2 * rot1 * sca; - -# transform mesh vertices -[x y z] = transformPoint3d(v, trans); - - -## Process output -if nargout == 0 - # no output: draw the cube - drawMesh([x y z], f, varargin{:}); - -elseif nargout == 1 - # one output: draw the cube and return handle - varargout{1} = drawMesh([x y z], f, varargin{:}); - -elseif nargout == 3 - # 3 outputs: return computed coordinates - varargout{1} = x; - varargout{2} = y; - varargout{3} = z; -end -
--- a/main/geometry/devel/meshes3d/createCube.m Mon Oct 22 16:58:48 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -## Copyright (C) 2004-2011 David Legland <david.legland@grignon.inra.fr> -## Copyright (C) 2004-2011 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) -## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> -## All rights reserved. -## -## Redistribution and use in source and binary forms, with or without -## modification, are permitted provided that the following conditions are met: -## -## 1 Redistributions of source code must retain the above copyright notice, -## this list of conditions and the following disclaimer. -## 2 Redistributions in binary form must reproduce the above copyright -## notice, this list of conditions and the following disclaimer in the -## documentation and/or other materials provided with the distribution. -## -## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' -## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR -## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -function varargout = createCube() -#CREATECUBE Create a 3D mesh representing the unit cube -# -# [V E F] = createCube -# Create a unit cube, as a polyhedra representation. -# c has the form [V E F], where V is a 8-by-3 array with vertices -# coordinates, E is a 12-by-2 array containing indices of neighbour -# vertices, and F is a 6-by-4 array containing vertices array of each -# face. -# -# [V F] = createCube; -# Returns only the vertices and the face vertex indices. -# -# MESH = createCube; -# Returns the data as a mesh structure, with fields 'vertices', 'edges' -# and 'faces'. -# -# Example -# [n e f] = createCube; -# drawMesh(n, f); -# -# See also -# meshes3d, drawMesh -# createOctahedron, createTetrahedron, createDodecahedron -# createIcosahedron, createCubeOctahedron -# -# --------- -# author : David Legland -# INRA - TPV URPOI - BIA IMASTE -# created the 10/02/2005. -# - -# HISTORY -# 04/01/2007: remove unused variables - -x0 = 0; dx= 1; -y0 = 0; dy= 1; -z0 = 0; dz= 1; - -nodes = [... - x0 y0 z0; ... - x0+dx y0 z0; ... - x0 y0+dy z0; ... - x0+dx y0+dy z0; ... - x0 y0 z0+dz; ... - x0+dx y0 z0+dz; ... - x0 y0+dy z0+dz; ... - x0+dx y0+dy z0+dz]; - -edges = [1 2;1 3;1 5;2 4;2 6;3 4;3 7;4 8;5 6;5 7;6 8;7 8]; - -# faces are oriented such that normals point outwards -faces = [1 3 4 2;5 6 8 7;2 4 8 6;1 5 7 3;1 2 6 5;3 7 8 4]; - -# format output -varargout = formatMeshOutput(nargout, nodes, edges, faces);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/inst/geom3d/createScaling3d.m Mon Oct 22 17:18:34 2012 +0000 @@ -0,0 +1,88 @@ +## Copyright (C) 2004-2011 David Legland <david.legland@grignon.inra.fr> +## Copyright (C) 2004-2011 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) +## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +## All rights reserved. +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are met: +## +## 1 Redistributions of source code must retain the above copyright notice, +## this list of conditions and the following disclaimer. +## 2 Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in the +## documentation and/or other materials provided with the distribution. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' +## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR +## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{trans} =} createScaling3d (@var{s}) +## @deftypefnx {Function File} {@var{trans} =} createScaling3d (@var{sx}, @var{sy}, @var{sz}) +## Create the 4x4 matrix of a 3D scaling +## +## TRANS = createScaling3d(S); +## returns the scaling transform corresponding to a scaling factor S in +## each direction. S can be a scalar, or a 1x3 vector containing the +## scaling factor in each direction. +## +## TRANS = createScaling3d(SX, SY, SZ); +## returns the scaling transform corresponding to a different scaling +## factor in each direction. +## +## The returned matrix has the form : +## @group +## [SX 0 0 0] +## [ 0 SY 0 0] +## [ 0 0 SZ 0] +## [ 0 0 0 0] +## @end group +## +## @seealso{transforms3d, transformPoint3d, transformVector3d, createTranslation3d, +## createRotationOx, createRotationOy, createRotationOz} +## @end deftypefn + +function trans = createScaling3d(varargin) + + # process input parameters + if isempty(varargin) + # assert uniform scaling in each direction + sx = 1; + sy = 1; + sz = 1; + elseif length(varargin)==1 + # only one argument + var = varargin{1}; + if length(var)==1 + # same scaling factor in each direction + sx = var; + sy = var; + sz = var; + elseif length(var)==3 + # scaling is a vector, giving different scaling in each direction + sx = var(1); + sy = var(2); + sz = var(3); + else + error('wrong size for first parameter of "createScaling3d"'); + end + elseif length(varargin)==3 + # 3 arguments, giving scaling in each direction + sx = varargin{1}; + sy = varargin{2}; + sz = varargin{3}; + else + error('wrong number of arguments for "createScaling3d"'); + end + + # create the scaling matrix + trans = [sx 0 0 0;0 sy 0 0;0 0 sz 0;0 0 0 1]; + +endfunction
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/inst/geom3d/drawCube.m Mon Oct 22 17:18:34 2012 +0000 @@ -0,0 +1,138 @@ +## Copyright (C) 2004-2011 David Legland <david.legland@grignon.inra.fr> +## Copyright (C) 2004-2011 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) +## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +## All rights reserved. +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are met: +## +## 1 Redistributions of source code must retain the above copyright notice, +## this list of conditions and the following disclaimer. +## 2 Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in the +## documentation and/or other materials provided with the distribution. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' +## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR +## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{h} =} drawCube (@var{cube}) +## @deftypefn {Function File} {[@var{x},@var{y},@var{z}] =} drawCube (@var{cube}) +## Draw a 3D centered cube, eventually rotated +## +## drawCube(CUBE) +## Displays a 3D cube on current axis. CUBE is given by: +## [XC YC ZC SIDE THETA PHI PSI] +## where (XC, YC, ZC) is the CUBE center, SIDE is the length of the cube +## main sides, and THETA PHI PSI are angles representing the cube +## orientation, in degrees. THETA is the colatitude of the cube, between 0 +## and 90 degrees, PHI is the longitude, and PSI is the rotation angle +## around the axis of the normal. +## +## CUBE can be axis aligned, in this case it should only contain center +## and side information: +## CUBE = [XC YC ZC SIDE] +## +## The function drawCuboid is closely related, but uses a different angle +## convention, and allows for different sizes along directions. +## +## Example +## @example +## # Draw a cube with small rotations +## figure; hold on; +## drawCube([10 20 30 50 10 20 30], 'FaceColor', 'g'); +## axis equal; +## view(3); +## @end example +## +## WARNING: This function doesn't work in gnuplot (as of version 4.2). +## +## @seealso{meshes3d, polyhedra, createCube, drawCuboid} +## @end deftypefn + +function varargout = drawCube(cube, varargin) + + # default values + theta = 0; + phi = 0; + psi = 0; + + ## Parses the input + if nargin == 0 + # no input: assumes cube with default shape + xc = 0; yc = 0; zc = 0; + a = 1; + + else + # one argument: parses elements + xc = cube(:,1); + yc = cube(:,2); + zc = cube(:,3); + a = cube(:,4); + + # parses orientation if present + k = pi / 180; + if size(cube, 2) >= 6 + theta = cube(:,5) * k; + phi = cube(:,6) * k; + end + if size(cube, 2) >= 7 + psi = cube(:,7) * k; + end + end + + + ## Compute cube coordinates + + # create unit centered cube + [v f] = createCube; + v = bsxfun(@minus, v, mean(v, 1)); + + # convert unit basis to cube basis + sca = createScaling3d (a); + rot1 = createRotationOz (psi); + rot2 = createRotationOy (theta); + rot3 = createRotationOz (phi); + tra = createTranslation3d ([xc yc zc]); + + # concatenate transforms + trans = tra * rot3 * rot2 * rot1 * sca; + + # transform mesh vertices + [x y z] = transformPoint3d (v, trans); + + + ## Process output + if nargout == 0 + # no output: draw the cube + drawMesh ([x y z], f, varargin{:}); + + elseif nargout == 1 + # one output: draw the cube and return handle + varargout{1} = drawMesh ([x y z], f, varargin{:}); + + elseif nargout == 3 + # 3 outputs: return computed coordinates + varargout{1} = x; + varargout{2} = y; + varargout{3} = z; + end + +endfunction + +%!demo +%! # Draw a cube with small rotations +%! close all +%! graphics_toolkit fltk; +%! figure; hold on; +%! drawCube([10 20 30 50 10 20 30], 'FaceColor', 'g'); +%! axis equal; +%! view(3);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/geometry/inst/meshes3d/createCube.m Mon Oct 22 17:18:34 2012 +0000 @@ -0,0 +1,85 @@ +## Copyright (C) 2004-2011 David Legland <david.legland@grignon.inra.fr> +## Copyright (C) 2004-2011 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) +## Copyright (C) 2012 Adapted to Octave by Juan Pablo Carbajal <carbajal@ifi.uzh.ch> +## All rights reserved. +## +## Redistribution and use in source and binary forms, with or without +## modification, are permitted provided that the following conditions are met: +## +## 1 Redistributions of source code must retain the above copyright notice, +## this list of conditions and the following disclaimer. +## 2 Redistributions in binary form must reproduce the above copyright +## notice, this list of conditions and the following disclaimer in the +## documentation and/or other materials provided with the distribution. +## +## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' +## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR +## ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +## SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +## CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +## OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +## -*- texinfo -*- +## @deftypefn {Function File} {[@var{v},@var{e},@var{f}] =} createCube () +## @deftypefn {Function File} {[@var{v},@var{f}] =} createCube () +## @deftypefnx {Function File} {@var{mesh} =} createCube () +## Create a 3D mesh representing the unit cube +## +## [V E F] = createCube +## Create a unit cube, as a polyhedra representation. +## c has the form [V E F], where V is a 8-by-3 array with vertices +## coordinates, E is a 12-by-2 array containing indices of neighbour +## vertices, and F is a 6-by-4 array containing vertices array of each +## face. +## +## [V F] = createCube; +## Returns only the vertices and the face vertex indices. +## +## MESH = createCube; +## Returns the data as a mesh structure, with fields 'vertices', 'edges' +## and 'faces'. +## +## Example +## @example +## [n e f] = createCube; +## drawMesh(n, f); +## @end example +## +## @seealso{meshes3d, drawMesh, createOctahedron, createTetrahedron, +## createDodecahedron, createIcosahedron, createCubeOctahedron} +## @end deftypefn + +function varargout = createCube() + + x0 = 0; dx= 1; + y0 = 0; dy= 1; + z0 = 0; dz= 1; + + nodes = [... + x0 y0 z0; ... + x0+dx y0 z0; ... + x0 y0+dy z0; ... + x0+dx y0+dy z0; ... + x0 y0 z0+dz; ... + x0+dx y0 z0+dz; ... + x0 y0+dy z0+dz; ... + x0+dx y0+dy z0+dz]; + + edges = [1 2;1 3;1 5;2 4;2 6;3 4;3 7;4 8;5 6;5 7;6 8;7 8]; + + # faces are oriented such that normals point outwards + faces = [1 3 4 2;5 6 8 7;2 4 8 6;1 5 7 3;1 2 6 5;3 7 8 4]; + + # format output + varargout = formatMeshOutput(nargout, nodes, edges, faces); + +endfunction + +%!demo +%! [n e f] = createCube; +%! drawMesh(n, f); +