Geometric Primitives and Geomtric Operations with Matlab

February 26, 2010 by Admin · Leave a Comment
Filed under: Computational Geometry, Geometry, Graphics 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 10.0/10 (1 vote cast)

Matlab does not come by default with a geometric primitives library. About for some simple function like the “sphere” command, using some geometric entities may be an issue. Fortunately on Matlab file exchange are available these two packages, from David Legland ,that help us to develop geometric projects.

The packages include functions for computations on planar and spatial geometrical shapes (points, lines, circles, polygons…)

The goal is to provide a low-level library for manipulating geometrical primitives, making easier the development of more complex geometric algorithms.

The library proposes functions to:

  • create various shapes (points, circles, lines, ellipses, polylines, polygons) using an intuitive syntax. Ex: createCircle(p1, p2, p3) to create a circle through 3 points.
  • derive new shapes: intersection between 2 lines, between a line and a circle, parallel and perpendicular lines
    Functions to compute intersections
  • work on polylines and polygons: compute centroid and area, expand, clip with half-plane…
  • measure distances (between points, a point and a line, a point and a group of points), angle (of a line, between 3 points), or test geometry (point on a line, on a circle).
  • manipulate planar transformation. Ex: P2 = transformPoint(P1, createRotation(CENTER, THETA));
  • draw shapes easily. Ex: drawCircle([50 50], 25), drawLine([X0 Y0 DX DY]). Some clipping is performed for infinite shapes such as lines or rays.
  • 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)
  • 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
VN:F [1.8.1_1037]
Rating: 10.0/10 (1 vote cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 3% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS

BuildSphere, get a sphere surface model

August 6, 2009 by Luigi Giaccari · 2 Comments
Filed under: Geometry, Graphics 
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)
VN:F [1.8.1_1037]
Rating: 8.0/10 (1 vote cast)

BuildSphere

This can be considered the triangular version of file exchange id 20888 which uses quad patches.

BUILDSPHERE:
Returns the triangulated model of a sphere using the icosaedron subdivision method.

INPUT:

  • n (integer number) indicates the number of subdivisions, it can assumes values between 0-inf. The greater n the better will look the surface but the more time will be spent in surface costruction and more triangles will be put in the output model.

OUTPUT:

  • In p (n x 3) and t(m x 3) we can find points and triangles indexes of the model. The sphere is supposed to be of unit radius and centered in (0,0,0). To obtain spheres centered in different location, or with different radius, is just necessary a translation and a scaling transformation. These operation are not performed by this code because it is extremely convenient, in order of time performances, to do them out of the function avoiding to call the costruction step each time.

NOTE:


This function is more efficient than the matlab command sphere in terms of dimension of the model/ accuracy of recostruction. This due to well triangulated model that requires a minor number of patches for the same geometrical recostruction accuracy. Possible improvement are possible in time execution and model subdivision flexibility.

EXAMPLE:

n=5;

[p,t]=BuildSphere(n);

figure(1)
axis equal
hold on
trisurf(t,p(:,1),p(:,2),p(:,3));
axis vis3d
view(3)

CONTACTS:

Author: Giaccari Luigi Created:25/04/2009

For info/bugs/questions/suggestions : giaccariluigi@msn.com


Download Now

VN:F [1.8.1_1037]
Rating: 8.0/10 (1 vote cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 26% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Live
  • PDF
  • Technorati
  • Twitter
  • Yahoo! Bookmarks
  • Add to favorites
  • email
  • MySpace
  • RSS