Rank: 3275 based on 36 downloads (last 30 days) and 2 files submitted
photo

dberm22

E-mail
Company/University
University of Maryland

Personal Profile:

 

Watch this Author's files

 

Files Posted by dberm22 View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
03 Oct 2013 RoundX - Round to desired precision Rounds the elements of X with the desired precision. Author: dberm22 round, ceil, floor, precision, decimal, places 16 0
  • 5.0
5.0 | 2 ratings
18 Aug 2011 Root Mean Squared This set of two functions returns the root mean squared of any 1-D signal. Author: dberm22 rms, frms, root mean squared, time domain, frequency domain, fft 20 5
  • 4.0
4.0 | 4 ratings
Comments and Ratings by dberm22 View all
Updated File Comments Rating
19 Dec 2014 Ray/Triangle Intersection Ray/triangle intersection using the algorithm proposed by Möller and Trumbore (1997) Author: Jesús P. Mena-Chalco

Works great, but too slow for what I needed. Mostly not your fault, but I needed to call this function more than a million times, and the built-in matlab routines you called were weighing it down.

I took your code and sped it up. for my test with 90,000 calls, it takes your function 16s, and mine only takes 1.5. That's a speedup of 10x! Here's what I have:

function [flag, u, v, t] = fastRayTriangleIntersection (o, d, p0, p1, p2)
% Ray/triangle intersection using the algorithm proposed by Möller and Trumbore (1997).
%
% Input:
% o : origin.
% d : direction.
% p0, p1, p2: vertices of the triangle.
% Output:
% flag: (0) Reject, (1) Intersect.
% u,v: barycentric coordinates.
% t: distance from the ray origin.
% Author:
% Originally written by Jesus Mena, edited by David Berman (dberm22@gmail.com)

epsilon = 0.00001;

e1 = p1-p0;
e2 = p2-p0;
q = [d(2)*e2(3)-d(3)*e2(2), d(3)*e2(1)-d(1)*e2(3), d(1)*e2(2)-d(2)*e2(1)]; %cross product
a = e1(1)*q(1)+e1(2)*q(2)+e1(3)*q(3); % determinant of the matrix M

if (a>-epsilon && a<epsilon)
% the vector is parallel to the plane (the intersection is at infinity)
flag=0;
u=0;
v=0;
t=0;
return;
end;

f = 1/a;
s = o-p0;
u = f*(s(1)*q(1)+s(2)*q(2)+s(3)*q(3));

if (u<0.0)
% the intersection is outside of the triangle
flag=0;
u=0;
v=0;
t=0;
return;
end;

r = [s(2)*e1(3)-s(3)*e1(2), s(3)*e1(1)-s(1)*e1(3), s(1)*e1(2)-s(2)*e1(1)];
v = f*(d(1)*r(1)+d(2)*r(2)+d(3)*r(3));

if (v<0.0 || u+v>1.0)
% the intersection is outside of the triangle
flag=0;
u=0;
v=0;
t=0;
return;
end;

t = f*(e2(1)*r(1)+e2(2)*r(2)+e2(3)*r(3)); % verified!
flag = 1;
return;
end

Thanks for the basis!

19 Dec 2014 Ray/Triangle Intersection Ray/triangle intersection using the algorithm proposed by Möller and Trumbore (1997) Author: Jesús P. Mena-Chalco

Works great, but too slow for what I needed. Mostly not your fault, but I needed to call this function more than a million times, and the built-in matlab routines you called were weighing it down.

I took your code and sped it up. for my test with 90,000 calls, it takes your function 16s, and mine only takes 2. That's a speedup of 8x! Here's what I have:

function [flag, u, v, t] = fastRayTriangleIntersection (o, d, p0, p1, p2)
% Ray/triangle intersection using the algorithm proposed by Möller and Trumbore (1997).
%
% Input:
% IMPORTANT: ALL INPUTS NEED TO BE 3 ELEMENT ROW VECTORS
% o : origin.
% d : direction.
% p0, p1, p2: vertices of the triangle.
% Output:
% flag: (0) Reject, (1) Intersect.
% u,v: barycentric coordinates.
% t: distance from the ray origin.
% Author:
% Originally written by Jesus Mena, edited by David Berman (dberm22@gmail.com)

epsilon = 0.00001;

e1 = p1-p0;
e2 = p2-p0;
q = [d(2)*e2(3)-d(3)*e2(2), d(3)*e2(1)-d(1)*e2(3), d(1)*e2(2)-d(2)*e2(1)]; %cross product
a = e1*q'; % determinant of the matrix M

if (a>-epsilon && a<epsilon)
% the vector is parallel to the plane (the intersection is at infinity)
flag=0;
u=0;
v=0;
t=0;
return;
end;

f = 1/a;
s = o-p0;
u = f*s*q';

if (u<0.0)
% the intersection is outside of the triangle
flag=0;
u=0;
v=0;
t=0;
return;
end;

r = [s(2)*e1(3)-s(3)*e1(2), s(3)*e1(1)-s(1)*e1(3), s(1)*e1(2)-s(2)*e1(1)];
v = f*d*r';

if (v<0.0 || u+v>1.0)
% the intersection is outside of the triangle
flag=0;
u=0;
v=0;
t=0;
return;
end;

t = f*e2*r'; % verified!
flag = 1;
return;
end

Only caveat is that all inputs need to be 3 element ROW vectors, and there is absolutely no error checking. If you can live with that, then this will do it!

Thanks for the basis!

26 Jun 2013 Color coded 3D scatterplot Produces a 3D scatterplot of XYZ data with varying colors Author: Ken Garrard

MUCH quicker than scatter3(). What a lifesaver!

24 Jun 2013 Plot (Big) Makes MATLAB's line plots much faster. Author: Tucker McClure

I did my own testing on this for speed, and at first I was tempted to give this 1 star because the tic-toc results show that reduce_plot() takes twice as long to create the plot than the regular plot() does. Don't be fooled by this! tic-toc does not take into account how long it takes to show the plot on the screen, for which reduce_plot() is extremely efficient. Also, with the such large amount of numbers I was using, zooming was rendered impossible with the normal plot() function. reduce_plot() was a life-saver in those scenarios.

plot() = 1.66s (create plot) + 7.54s (show on screen) = 9s total (& cannot zoom)
reduce_plot = 3.65s (create plot) + .8s (show on screen) = 4.45s total + .7s (zooming) = priceless

28 May 2013 Iterative Closest Point An implementation of various ICP (iterative closest point) features. Author: Jakob Wilm

Exactly what I was looking for! Perfect!

Comments and Ratings on dberm22 's Files View all
Updated File Comment by Comments Rating
11 Jun 2014 RoundX - Round to desired precision Rounds the elements of X with the desired precision. Author: dberm22 Eoghan

04 Oct 2013 RoundX - Round to desired precision Rounds the elements of X with the desired precision. Author: dberm22 Anne Tishley

20 Sep 2011 Root Mean Squared This set of two functions returns the root mean squared of any 1-D signal. Author: dberm22 Anne Tishley

Works fine. No Frills.

20 Sep 2011 Root Mean Squared This set of two functions returns the root mean squared of any 1-D signal. Author: dberm22 dberm22

Thanks for the feedback, Shaun

20 Sep 2011 Root Mean Squared This set of two functions returns the root mean squared of any 1-D signal. Author: dberm22 Shaun

Simple, but works brilliantly. Thanks for the explanation on the license, dberm.

Contact us