Code covered by the BSD License  

Highlights from
geom3d

5.0

5.0 | 9 ratings Rate this file 146 Downloads (last 30 days) File Size: 274.72 KB File ID: #24484
image thumbnail

geom3d

by David Legland

 

19 Jun 2009 (Updated 13 Oct 2011)

Library to handle 3D geometric primitives: create, intersect, display, and make basic computations

| Watch this File

File Information
Description

The aim of geom3d library is to handle and visualize 3D geometric primitives such as points, lines, planes, polyhedra... It provides low-level functions for manipulating 3D geometric primitives, making easier the development of more complex geometric algorithms.

Some features of the library are:

- creation of various shapes (3D points, 3D lines, planes, polyhedra...) through an intuitive syntax. Ex:
  createPlane(p1, p2, p3) to create a plane through 3 points.

- derivation of new shapes: intersection between 2 planes, intersection between a plane and a line, between a sphere and a line...

- functions for 3D polygons and polyhedra. Polyhedra use classical vertex-faces arrays (face array contain indices of vertices), and support faces with any number of vertices. Some basic models are provided (createOctaedron, createCubeoctaedron...), as well as some computation (like faceNormal or centroid)

- manipulation of planar transformation. Ex.:
   ROT = createRotationOx(THETA);
   P2 = transformPoint3d(P1, ROT);

- direct drawing of shapes with specialized functions. Clipping is performed automatically for unbounded shapes such as lines or rays. Ex:
    drawPoint3d([50 50 25; 20 70 10], 'ro'); % draw some points
    drawLine3d([X0 Y0 Z0 DX DY DZ]); % clip and draw straight line

The library is divided into two packages:
* geom3d for general computation in 3d
* meshes3d for representation and manipulation of polyhedral meshes

Several functions require the geom2d package, available on the FEx.
     
Additional help is provided in geom3d/Contents.m and meshes3d/Contents.m files, as well as summary files like 'points3d.m' or 'lines3d.m'.

Acknowledgements
This submission has inspired the following:
intersectPlaneSurf II
MATLAB release MATLAB 7.9 (2009b)
Other requirements Some functions require the geom2d library, also on the File Exchange (ID 7844)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (21)
19 Jun 2009 us

it is too bad that this (apparently) full-fledged software package does not come with an appropriate and modern help/intro/example module called a published m-file...

as of now, it is somewhat tedious for a naive user to have to wade through the help sections of the individual help files (or the densly written contents.m) - and it will (most likely) not give your package as much attention as it probably deserves...

us

17 Jul 2009 Nathan Thern

This library and its companion, geom2d, are shining jewels - indispensable for doing non-trivial calculations on objects in 2d and 3d space.

By the way, leave all the files in the geom3d directory and add the directory to your path. Then you can type "help geom3d" or "doc geom3d" and get properly linked help text in the command window or the help window. The Contents.m file is the proper "MATLAB way" of providing documentation.

03 Aug 2009 Jon Sporring

This package aims at solving visualization problems, I often have. However, I have not been able to I'm trying to use this package, but experiencing a number of problems:

1. How are the colors controlled of the objects drawn?
2. I want to draw cylindrical representation of arrows, since quiver3 together with drawPlane does not work well, possibly due to lack of control of drawing order. Instead I want to draw thick arrows, and I'm using drawCylinder.m. However, in line 89 is used the non-existing function local2Global.m. It appears to be replaceable by localToGlobal3d, if localToGlobal3d line 29 is replaced with "center = varargin{1};".

For suggestions to corrections, etc. what is the best procedure?

Thanks, Jon

01 Sep 2009 David Legland

Hi,
I have uploaded a new version, that fixes reported bugs, and have added some demos. Demos are available as published m-files, and can be accessed through the file presentation above. They demonstrates some usage possibilities.

Most drawing functions follow the 'plot' syntax. Data are given first, then optional couples of parameter name and value. If not implemented, try using "h=drawMyShape(...)", then set up options using "set(h, 'color', 'k')" for example.

For bug reports and suggestions, the best is to sent me directly and e-mail (can be found in my author page, replace "DOT" by ".").

DL

03 Dec 2009 Paklah Abd Rahman

Hi,

I tried the "intersectLineCylinder" what are the definitions of: xa, ya, za, and L for cylinder??..Please anybody

07 Dec 2009 David Legland

The format for cylinder is as follow: [xv yv zy R xc yc zc], with:
[xv yv zv] the direction vector of the cylinder,
R the radius of the cylinder
[xc yc zc] the origin of the cylinder.
the L parameter, which is given in help, is not used.
The cylinder is considered infinite, please use "linePosition3d" if you need finite cylinder.
Please note that this format is not consistent with the function "drawCylinder", for example. Therefore the function "intersectLineCylinder" is likely to change in a future release.
DL

11 Dec 2009 Sven

Excellent package for spatial manipulation. Extensive toolbox, that handles input intuitively. The only suggestion I have is, for completeness, to document some of the methods of calling functions for the more obscure functions. Eg., localToGlobal3d has one documented method of calling, but under the hood it parses input in many different ways. I find myself typing "edit" instead of "help" just to make sure I'm using things efficiently.

06 May 2010 Siyi Deng

very helpful.

01 Dec 2010 Brady

Incredibly helpful toolbox. Mostly intuitive function calls, and thorough documentation to make integration easy.

19 Jan 2011 Brandon  
15 Feb 2011 Khaled

Dear eng. David,

Thanks, this powerful toolbox is very helpful.

I tried to create a 3D polygon from four or three 3D points, and couldn't. So instead I tried to create a plane, but when finding an intersection with a 3D line the answer will not be accurate as the plane was polygon.

Is there a possible way to create a 3D polygon from four or three points? and
Is there a possible way to find a intersection between a 3D line and 3D polygon?

your efforts are appreciated.

16 Feb 2011 David Legland

Hi Khaled,
to create a 3D polygon, you simply need to concatenate their coordinates into a N-by-3 array, e.g. poly=cat(1,p1,p2,p3);
There are no fucntions for intersections of 3D line with 3D polygon. The best is to use 3D plane, and eventually to project all points on the plane, then to use function for 2D polygons.

21 May 2011 Qais AlKhazraji

Dear David:
I read your comment for Khaled question. It is not clear to me about what you said"The best is to use 3D plane, and eventually to project all points on the plane, then to use function for 2D polygons." Which points we should project on 3D plane and from my understanding line intersect a polygon in one point.
Thank you in advance

22 May 2011 David Legland

@Khaled and Qais,
What I had in mind was to use the following procedure :
* compute intersection of line and polygon plane
* project polyingon vertices onto the plane (ie, compute their 2D coords)
* project intersection point onto the plane
* check if 2D intersection point is within the 2D polygon.
The following piece of code should do the job (assuming poly3d is N-by-3 and line is 1-by-6):
 plane = createPlane(poly3d(1:3, :));
 inter = intersectLinePlane(line, plane);
 poly2d = projPointOnPlane(poly3d, plane);
 pInt2d = projPointOnPlane(inter, plane);
 inside = xor(isPointInPolygon(pInt2d, poly2d), polygonArea(poly2d) < 0);
 inter = inter(inside, :);

Both geom2d and geom3d are required. I will add functions 'intersectLinePolygon3d' and 'intersecRayPolygon3d' in the next release.

regards

19 Jul 2011 Qais AlKhazraji

Dear David,
I am just start using Matlab in my research for geometrical computation. I appreciate if you would like to demonstarate how to use this library(3d or 2d) since each function I used give me syntax error about other functions as undefined. I am a biginner in Matlab and may be my question is dump question. I am very thankful.

20 Jul 2011 David Legland

@Qais,
you should install both geom2d and geom3d, typically in the same directory. Then you have to add directories to the path, using te 'addpath' function, or the 'File->Set Path' menu). You need to add at least the directories 'geom2d', 'geom3d', 'polygons2d', 'meshes3d', and eventually 'polynomialCurves2d'.

Some demos are provided with each archive, you can run them directly, and have an idea on the syntax.

I will also try to add some info on the matGeom web page (that gathers geom2d and geom3d), at http://matgeom.sourceforge.net .

Hope this helps

07 Aug 2011 Sakshi  
13 Dec 2011 Shuhao Cao  
07 Feb 2012 Patrik Eschle

Nicely written, good comments - thank you!

08 Feb 2012 Patrik Eschle

distanceLine3d works on infinite lines a+t*b. Sometimes (collision detection) the distance between line segments AB and CD is required. A distanceSegment3d would be useful.

The same is true for points (distancePointSegment ).

Or did I just miss it?

10 Feb 2012 David Legland

Hi Patrik,

no, you haven't missed it, and it could be useful. I will add it in a future release.

regards

Please login to add a comment or rating.
Updates
26 Aug 2009

some bug fixes, demo files as published m-files.

31 Aug 2009

add missing demos

29 Jul 2010

fixed bugs in rotations and in drawing of some shapes, added rotation by Euler angles, various update in doc and in code

14 Jan 2011

Add new functions for meshes and polyhedra, and for 3D transforms (rotations, basis transform). See file changelog.txt

30 Jun 2011

use degrees for drawing shapes, split lib into packages 'geom3d' and meshes3d

13 Oct 2011

various code cleanup and speed improvements, mainly contributed by Sven Holcombe (many thanks!)

Tag Activity for this File
Tag Applied By Date/Time
geometry David Legland 19 Jun 2009 11:47:28
3d David Legland 19 Jun 2009 11:47:28
geometric computing David Legland 19 Jun 2009 11:47:28
polygon David Legland 19 Jun 2009 11:47:28
plane David Legland 19 Jun 2009 11:47:28
polyhedron David Legland 19 Jun 2009 11:47:28
polyhedra David Legland 19 Jun 2009 11:47:28

Contact us at files@mathworks.com