Jimmy's blog stuff http://blog.jimmyhchan.com a todo list of sorts posterous.com Mon, 01 Mar 2010 10:49:00 -0800 Chile vs Haiti earthquakes: is not 8.8 vs 7.0. Donate money to Haiti http://blog.jimmyhchan.com/chile-vs-haiti-earthquakes-is-not-88-vs-70-do http://blog.jimmyhchan.com/chile-vs-haiti-earthquakes-is-not-88-vs-70-do
Q: Two countries were struck by large earthquakes: one of magnitude 8.8 and one of magnitude 7.0.  You are the Red Cross, who would you give aid to?

A: WHAT?!  That's a ridiculous question!  You want me to decide using only a mathematical number?  What about telling me how many people died? or how many building collapsed? or how adequate are the hospitals---hell ... have the hospitals collapsed in the quake... ahhh! were there hospitals to begin with??!?

8.8 > 7.0 right?  What's the problem? 
Short answer: Scientists like scien-terrific numbers but you like useful numbers.  

The number in question is the Moment Magnitude, M_w (http://en.wikipedia.org/wiki/Moment_magnitude).  Chile had an 8.8 magnitude earthquake.  Haiti had a 7.0 magnitude earthquake.  It's a beautiful number (for scientists) -- every earthquake can be reduced to a single number and that number is in units of energy, the same units as nukes, car engines and chemical reactions.  M_w can be generated instantly using seismographs (read the peak acceleration, velocity; move some bits; carry the 1 ==>output Magnitude). Easy.  

Unfortunately, the number is completely useless to you. 

The moment magnitude (8.8 for Chile and 7.0 for Haiti) is only a number which relates to the energy the moving earth can generate. This would be a useful number for harnessing "earthquake power!" or for answering "how strong is god" but not as useful for what you care about -- Should I give aid to country A or country B... you know straight effects-on-buildings-and-p eople comparisons. 

**sidenote: The old Richter scale is similar but uses a different mathematical formula (That is they are different numbers).  Today, all magnitudes are moment magnitudes but Richter magnitudes are still around... just to add confusion.  [[ Edit 2Mar10 : The moment magnitude (in energy units) is actually scaled to fit the Richter scale and are pretty close for low (less than M=7) magnitudes but start diverting at higher magnitudes.  The Richter scale is generally boundless so you get crazy magnitudes like 10.2]]

The problem with looking only at Magnitudes
The magnitude is just one number: the energy.  More specifically the energy released along the entire fault.  The magnitude of an earthquake does not tell you anything about Aunty Betsy's apartment complex 500 miles from the epicenter or Uncle Bob's high rise office built on the old landfill 20 miles southeast of the fault.  
Everything from the earthquakes travel to the surface will affect what it does.  This includes the direction of the fault, the quality of the soil, the quality of the building, the preparedness of the people and the amount of support post-quake.  Again, we care about Aunt Betsy and Uncle Bob, not alternative energy from tectonic plates. 

What should we look at instead? Mercalli Intensity     
The maths for comparing magnitudes is crazy and altogether not quite useful. There is another number though which gives you the effects of an earthquake: the Modified Mecalli Intensity (MMI) http://en.wikipedia.org/wiki/Mercalli_intensity_scale .  MMI is a subjective human description of the earthquake from different areas around the epicenter. This more "human scale" accounts for proximity to the epicenter, soil conditions, building construction, population density etc. using a very complex machine: You.  You, or people in general, determine this number by feeling the earthquake and looking around and making the analysis of "OMG this place is destroyed who dropped the nuke (XII)" or "WTF my favorite tea cup fell down (IV)" .  

It's the same as the USGS's "did you feel it" maps. 

[[ Edit 2Mar10: these two maps help clear things up http://earthquake.usgs.gov/earthquakes/shakemap/global/shake/2010tfan/
So this scale make it easier to compare earthquakes on a human scale. Awesome! ....but it's subjective.  According to wikipedia, Santiago, Chile was a VII (very strong) but closer cities were an VIII (Destructive). Haiti's Port-au-Prince was a IX(Ruinous) and there were large population areas in areas of X (Disastrous).  Whereas Moment magnitude is a scientific number which accepted by Americans, Chileans and Haitians seismologists alike, the Mercalli Intensity if different depending on who you ask (on an individual, neighborhood and country scale, Chile's scientists think the MMI is higher than the USGS.)

Also, the only way to get MMI maps is by having people fill out a survey and that not easy for big earthquakes in rural areas.  So the MMI comparisons are useful but not quite scien-terrific.

Other things to consider?
Earthquakes in the US today will not cause the number of fatalities as an earthquake in Haiti.  Why?  Building requirements are more stringent and hospitals are readily available.  
We can't make earthquakes stop so we need to fix governments and people.  Promote preparedness, push awareness and provide support.  Even small earthquakes can be devastating in societies not ready for it.

Action
Even though the magnitude scale is a silly bunch of maths, we should still act.  Please be prepared, be aware and donate to red cross http://www.redcross.org/.   

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Thu, 11 Feb 2010 11:24:00 -0800 Big list of FAQ for programmers from Reddit Programming: I'm job interviewing and need a bunch of resources http://blog.jimmyhchan.com/big-list-of-faq-for-programmers-from-reddit-p http://blog.jimmyhchan.com/big-list-of-faq-for-programmers-from-reddit-p

The subreddit programming on reddit.com has always been an treasure trove of wonderful, sometimes quirky but always useful and interesting information.  Unfortunately, the same stuff keeps popping up and it's hard to sift through the junk.  

The FAQ for programming.reddit   http://www.reddit.com/help/faqs/programming  A large list of awesome


I'm currently looking at web development / programming jobs so here's a list of things I found interesting:

Blogs: 
  • A List Apart - http://www.alistapart.com/  on the design, development, and meaning of web content
  • Joel's blog and Jeff's blog --- but I think the stackoverflow podcast is more interesting
Interviews/Job: 
Web Hosting Alternatives
Nobody enjoys being with godaddy -- for ethical reasons (they support republicans, they shutdown sites for random reasons, they take your domain and auction it) and for service reasons (limited software and limited support)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Sat, 29 Aug 2009 13:41:53 -0700 List of linux apps http://blog.jimmyhchan.com/list-of-linux-apps http://blog.jimmyhchan.com/list-of-linux-apps

http://www.dedoimedo.com/computers/new-cool-list-linux.html

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Tue, 11 Aug 2009 06:12:45 -0700 Escript / Finley releases version 3.0 http://blog.jimmyhchan.com/escript-finley-releases-version-30 http://blog.jimmyhchan.com/escript-finley-releases-version-30 Escript and Finely just released version 3.0.

 According to the pypi site(http://pypi.python.org/pypi/escript/):

   escript is a python based environment for implementing
mathematical models in particular those based on coupled, non-linear,
time-dependent partial differential equation. Parallelization with
both OpenMP and MPI is supported.
http://www.opensource.org/licenses/osl-3.0.php OSL license.

 The 3.0 user's guide describes it as:

 It consists of four major components

   * esys.escript core library
  * finite element solver esys.finley (which uses fast
vendor-supplied solvers or our paso linear solver library)
  * the meshing interface esys.pycad
  * a model library.

 There is a Finite Element code implemented with escript called Finley.
 There looks to be support for gmsh (mesher) and output visualization
using matplotlib (matlab-like plotter) and VTK (visualization
toolkit).

 Code site: https://launchpad.net/escript-finley
Documentation and examples : http://esys.esscc.uq.edu.au/docs.html

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Sun, 19 Jul 2009 17:44:13 -0700 List or Misc Compsci papers via Reddit http://blog.jimmyhchan.com/list-or-misc-compsci-papers-via-reddit http://blog.jimmyhchan.com/list-or-misc-compsci-papers-via-reddit http://www.reddit.com/r/programming/comments/9220o/ask_proggit_recommender_a_...

 Someone posted a request to the programming subreddit for compsci
papers to read over a weekend. There is a big list of papers from all
sorts of places.

 Some that I found interesting:

   Steele and Sussman's The Art of the Interpreter
http://repository.readscheme.org/ftp/papers/ai-lab-pubs/AIM-453.pdf
  Cook, Carpenter and Catmull's The Reyes Rendering
Architecture http://graphics.pixar.com/library/Reyes/paper.pdf
  Courant's Variational Methods for the Solution of Problems of
Equilibrium and Vibrations
http://home.agh.edu.pl/%7Emilenin/programs/doc/Courant_1943.pdf
  Baraff's Linear-Time Dynamics using Lagrange Multipliers
http://www.cs.cmu.edu/~baraff/papers/sig96.pdf
  The implementation of Lua 5.0
http://www.tecgraf.puc-rio.br/~lhf/ftp/doc/jucs05.pdf
  Efficient implementation of the smalltalk-80 system
http://citeseer.ist.psu.edu/old/540956.html

 It is interesting that there are so many seminal papers in computer
science. One day I'll read some old school Timoshenko
http://en.wikipedia.org/wiki/Stephen_Timoshenko.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Tue, 07 Jul 2009 14:39:29 -0700 Maybe I should be a tools developer http://blog.jimmyhchan.com/maybe-i-should-be-a-tools-developer http://blog.jimmyhchan.com/maybe-i-should-be-a-tools-developer From Toolsmith a special interest group (SIG) from IGDA

 Making a game or an animation movie is pretty hardcore but making
tools that make the games and animations is even more hardcore. I
wish I was this good.

  
The ToolsSig blog has a post on Eskil Steenberg and his tools for his game Love.
http://toolssig.wordpress.com/2009/04/28/tools-of-love/

 This is awesome and I hope that every UI can be this amazing.

 Apparently this is based on uni-verse an opensource application
http://uni-verse.org/Developers.5.0.html

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Sat, 04 Jul 2009 01:37:49 -0700 Videos on Javascript from Douglas Crockford http://blog.jimmyhchan.com/videos-on-javascript-from-douglas-crockford http://blog.jimmyhchan.com/videos-on-javascript-from-douglas-crockford From the top review of JavaScript the Good Parts by Douglas Crockford
http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742/r...

  
links added

 
There are a series of Yahoo! videos by Crockford that mirror the
material in this book and can be found as podcasts under YUI Theater.
They contain nearly all of the material in the book and probably a
little more. Those videos are:

 - Douglas Crockford/An Inconvenient API: The Theory of the DOM (3
parts) http://video.yahoo.com/watch/111582/992708
http://video.yahoo.com/watch/111583/996002
http://video.yahoo.com/watch/111584/996008
- Douglas Crockford/The JavaScript Programming Language (4 parts)
http://video.yahoo.com/watch/111593/1710507
http://video.yahoo.com/watch/111594/1710553
http://video.yahoo.com/watch/111595/1710607
http://video.yahoo.com/watch/111596/1710658
- Douglas Crockford/Advanced JavaScript (3 parts)
http://video.yahoo.com/watch/111585/1027823
http://video.yahoo.com/watch/111586/1027832
http://video.yahoo.com/watch/111587/1027854
- Douglas Crockford/Javascript The Good Parts
http://video.yahoo.com/watch/630959/2974197

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Sat, 09 May 2009 13:54:45 -0700 Blender Courses Tutorial and links http://blog.jimmyhchan.com/blender-courses-tutorial-and-links http://blog.jimmyhchan.com/blender-courses-tutorial-and-links
Blenducation

Blender is __the__ open source animation tool. It allows for
scripting in python. They've recently added a game engine.
 
Benducation
http://blenducation.org/wordpress/
 lots of tutorials and classes
 
Tuft's Blender course
http://www.gryllus.net/Blender/3D.html
 
youtube has a bunch (there's a 10 year old kid who has some good tutorials)

 
Blender nation is an amazing site as well
http://www.blendernation.com/
 
Blender's movies are fun to watch
Big Buck Bunny and Elephant's dream (peach and orange)
http://www.blender.org/features-gallery/movies/
 
Got to watch 'em all.
P.S. Wings3d
http://www.wings3d.com/

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Sat, 09 May 2009 13:48:50 -0700 Computer Science Courses http://blog.jimmyhchan.com/computer-science-courses http://blog.jimmyhchan.com/computer-science-courses From a reddit link

 CS courses are all over the place.
http://academicearth.org/subjects/computer-science/page:1/category:14
http://lecturefox.com/computerscience/

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Tue, 28 Apr 2009 14:31:25 -0700 Nvidia's Cg and GPU Gems book online for free http://blog.jimmyhchan.com/nvidias-cg-and-gpu-gems-book-online-for-free http://blog.jimmyhchan.com/nvidias-cg-and-gpu-gems-book-online-for-free
Gpu_gems_3_icon

Nvidia sponsored books GPU Gems are availabe online!
 
 
GPU Gems are often cited in computer graphics papers. A lot of
references for how to model crazy graphics stuff like water, fire,
cloth are there. It's essentially a place showing off Nvidia and
academic's research. Think Siggraph for the GPU and their shader
language.
 
GPU Gems 1: http://http.developer.nvidia.com/GPUGems/gpugems_part01.html
GPU Gems 2: http://http.developer.nvidia.com/GPUGems2/gpugems2_part01.html
GPU Gems 3: http://http.developer.nvidia.com/GPUGems3/gpugems3_part01.html
 
Nvidia also has a tutorial book on their shader language Cg available
online. http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter01.html

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Thu, 09 Apr 2009 17:30:09 -0700 Programmer competency matrix http://blog.jimmyhchan.com/programmer-competency-matrix http://blog.jimmyhchan.com/programmer-competency-matrix http://www.indiangeek.net/programmer-competency-matrix/
from a tweet by @codinghorror.

 conclusion i'm not even close.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Sun, 22 Mar 2009 09:40:50 -0700 Matrix and Quaternion FAQ: 3D Games Maths; Game Objects Code http://blog.jimmyhchan.com/matrix-and-quaternion-faq-3d-g http://blog.jimmyhchan.com/matrix-and-quaternion-faq-3d-g http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrf...

 Some Highlights:
FAQ 1: OpenGL is column centric
http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrf...
. This affects only how you learn the maths of it so just be aware
Read this http://steve.hollasch.net/cgindex/math/matrix/column-vec.html

 FAQ 35: Which order do you combine rotations?
http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrf...
 This is important since rotating in different orders results in
different orientations. the X Y Z order is common but there are
others XYX etc.

 FAQ 44: Linerar interpolation between rotation matrices
http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrf...

 Quaternions http://web.archive.org/web/20041029003853/http://www.j3d.org/matrix_faq/matrfaq_latest.html#Q47
 this is the strange maths that help in optimizing 3d graphics

 This was found by looking at Will McGugan's site
http://www.willmcgugan.com/projects/ and his project Game objects
http://code.google.com/p/gameobjects/ a python library similar to
Euclid http://pyeuclid.googlecode.com/svn/trunk/euclid.py

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Fri, 20 Mar 2009 04:21:15 -0700 PygameSF inteviews Pyglet Creator Alex Holkner http://blog.jimmyhchan.com/pygamesf-inteviews-pyglet-crea http://blog.jimmyhchan.com/pygamesf-inteviews-pyglet-crea PygameSF inteviews Pyglet Creator Alex Holkner
"If you have ever considered making a game with python chances are
while researching the options available you came across both the
Pygame and Pyglet libraries. "
http://www.pygamesf.org/?p=101

  

 A super interesting read and interview.

 A great resource is the user's group on google
http://groups.google.com/group/pyglet-users?pli=1

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Sun, 15 Mar 2009 18:25:08 -0700 Separating Axis Objects in contact http://blog.jimmyhchan.com/separating-axis-objects-in-con http://blog.jimmyhchan.com/separating-axis-objects-in-con Looking for a Separating Axis algorithm/understanding.

 found This http://gns.wikia.com/wiki/Separating_axes

  Essentially, separating axis method is a way to determine if two
objects are in contact. This is useful for collision detection in
games and simulation software.

 The idea is such: if you look at two objects and if you find that they
DO NOT overlap when looking from some angle (axis), then they are
definitely NOT in contact. If you find they ARE touching (from some
view), they MAY be in contact. So how may of these views do you need
to test before you KNOW they are in contact? Well it depends on the
shapes. There are specific viewing angles (axes) you can check to
make sure that, if they are touching in all cases, then they are
indeed in contact. Most of the axes are along the object/tangent or
a cross product of the two objects.

 Let's see if the Games and Simulation wikia wiki gets further developed.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Fri, 13 Mar 2009 01:10:26 -0700 3D Geometry code and good references http://blog.jimmyhchan.com/3d-geometry-code-and-good-refe http://blog.jimmyhchan.com/3d-geometry-code-and-good-refe I was looking for a Triangle Box intersection code to solve a problem
which I think is defined as a Euclidean shortest path problem in 3D
space which apparently is hard, really hard.

 Triangle box overlap algorithm
http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/tribox3.txt

  
My search led to to some terms:
* visibility graphs
* Continuous Dijkstra
* AABB
* ERIT
* BSP Tree
* Piano Movers
* Spider and Fly
* Geodesic

 and some good sites.
http://www.cs.lth.se/home/Tomas_Akenine_Moller/code/
HIs book "Real time Rendering"
http://books.google.com/books?id=mOKEfBTw4x0C&printsec=frontcover&dq=Fast+3D+...
chapter 13 (a 3rd edition is out)
http://www.realtimerendering.com/intersections.html site for his book.

/********************************************************/
 
/* AABB-triangle overlap test code */
 
/* by Tomas Akenine-Möller */
 
/* Function: int triBoxOverlap(float boxcenter[3], */
 
/* float boxhalfsize[3],float triverts[3][3]); */
 
/* History: */
 
/* 2001-03-05: released the code in its first version */
 
/* 2001-06-18: changed the order of the tests, faster */
 
/* */
 
/* Acknowledgement: Many thanks to Pierre Terdiman for */
 
/* suggestions and discussions on how to optimize code. */
 
/* Thanks to David Hunt for finding a ">="-bug! */
 
/********************************************************/
 
#include
 
#include
 
 
 
#define X 0
 
#define Y 1
 
#define Z 2
 
 
 
#define CROSS(dest,v1,v2) \
 
  dest[0]=v1[1]*v2[2]-v1[2]*v2[1]; \
 
  dest[1]=v1[2]*v2[0]-v1[0]*v2[2]; \
 
  dest[2]=v1[0]*v2[1]-v1[1]*v2[0];
 
 
 
#define DOT(v1,v2) (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2])
 
 
 
#define SUB(dest,v1,v2) \
 
  dest[0]=v1[0]-v2[0]; \
 
  dest[1]=v1[1]-v2[1]; \
 
  dest[2]=v1[2]-v2[2];
 
 
 
#define FINDMINMAX(x0,x1,x2,min,max) \
 
 min = max = x0; \
 
 if(x1max) max=x1;\
 
 if(x2max) max=x2;
 
 
 
int planeBoxOverlap(float normal[3], float vert[3], float maxbox[3]) // -NJMP-
 
{
 
 int q;
 
 float vmin[3],vmax[3],v;
 
 for(q=X;q 
 {
 
  v=vert[q]; // -NJMP-
 
  if(normal[q]>0.0f)
 
  {
 
  vmin[q]=-maxbox[q] - v; // -NJMP-
 
  vmax[q]= maxbox[q] - v; // -NJMP-
 
  }
 
  else
 
  {
 
  vmin[q]= maxbox[q] - v; // -NJMP-
 
  vmax[q]=-maxbox[q] - v; // -NJMP-
 
  }
 
 }
 
 if(DOT(normal,vmin)>0.0f) return 0; // -NJMP-
 
 if(DOT(normal,vmax)>=0.0f) return 1; // -NJMP-
 
 
 
 return 0;
 
}
 
 
 
 
 
/*======================== X-tests ========================*/
 
#define AXISTEST_X01(a, b, fa, fb) \
 
  p0 = a*v0[Y] - b*v0[Z]; \
 
  p2 = a*v2[Y] - b*v2[Z]; \
 
  if(p0rad || max 
 
 
#define AXISTEST_X2(a, b, fa, fb) \
 
  p0 = a*v0[Y] - b*v0[Z]; \
 
  p1 = a*v1[Y] - b*v1[Z]; \
 
  if(p0rad || max 
 
 
/*======================== Y-tests ========================*/
 
#define AXISTEST_Y02(a, b, fa, fb) \
 
  p0 = -a*v0[X] + b*v0[Z]; \
 
  p2 = -a*v2[X] + b*v2[Z]; \
 
  if(p0rad || max 
 
 
#define AXISTEST_Y1(a, b, fa, fb) \
 
  p0 = -a*v0[X] + b*v0[Z]; \
 
  p1 = -a*v1[X] + b*v1[Z]; \
 
  if(p0rad || max 
 
 
/*======================== Z-tests ========================*/
 
 
 
#define AXISTEST_Z12(a, b, fa, fb) \
 
  p1 = a*v1[X] - b*v1[Y]; \
 
  p2 = a*v2[X] - b*v2[Y]; \
 
  if(p2rad || max 
 
 
#define AXISTEST_Z0(a, b, fa, fb) \
 
  p0 = a*v0[X] - b*v0[Y]; \
 
  p1 = a*v1[X] - b*v1[Y]; \
 
  if(p0rad || max 
 
 
int triBoxOverlap(float boxcenter[3],float boxhalfsize[3],float triverts[3][3])
 
{
 
 
 
 /* use separating axis theorem to test overlap between triangle and box */
 
 /* need to test for overlap in these directions: */
 
 /* 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle */
 
 /* we do not even need to test these) */
 
 /* 2) normal of the triangle */
 
 /* 3) crossproduct(edge from tri, {x,y,z}-directin) */
 
 /* this gives 3x3=9 more tests */
 
  float v0[3],v1[3],v2[3];
 
// float axis[3];
 
  float min,max,p0,p1,p2,rad,fex,fey,fez; // -NJMP- "d" local variable removed
 
  float normal[3],e0[3],e1[3],e2[3];
 
 
 
  /* This is the fastest branch on Sun */
 
  /* move everything so that the boxcenter is in (0,0,0) */
 
  SUB(v0,triverts[0],boxcenter);
 
  SUB(v1,triverts[1],boxcenter);
 
  SUB(v2,triverts[2],boxcenter);
 
 
 
  /* compute triangle edges */
 
  SUB(e0,v1,v0); /* tri edge 0 */
 
  SUB(e1,v2,v1); /* tri edge 1 */
 
  SUB(e2,v0,v2); /* tri edge 2 */
 
 
 
  /* Bullet 3: */
 
  /* test the 9 tests first (this was faster) */
 
  fex = fabsf(e0[X]);
 
  fey = fabsf(e0[Y]);
 
  fez = fabsf(e0[Z]);
 
  AXISTEST_X01(e0[Z], e0[Y], fez, fey);
 
  AXISTEST_Y02(e0[Z], e0[X], fez, fex);
 
  AXISTEST_Z12(e0[Y], e0[X], fey, fex);
 
 
 
  fex = fabsf(e1[X]);
 
  fey = fabsf(e1[Y]);
 
  fez = fabsf(e1[Z]);
 
  AXISTEST_X01(e1[Z], e1[Y], fez, fey);
 
  AXISTEST_Y02(e1[Z], e1[X], fez, fex);
 
  AXISTEST_Z0(e1[Y], e1[X], fey, fex);
 
 
 
  fex = fabsf(e2[X]);
 
  fey = fabsf(e2[Y]);
 
  fez = fabsf(e2[Z]);
 
  AXISTEST_X2(e2[Z], e2[Y], fez, fey);
 
  AXISTEST_Y1(e2[Z], e2[X], fez, fex);
 
  AXISTEST_Z12(e2[Y], e2[X], fey, fex);
 
 
 
  /* Bullet 1: */
 
  /* first test overlap in the {x,y,z}-directions */
 
  /* find min, max of the triangle each direction, and test for overlap in */
 
  /* that direction -- this is equivalent to testing a minimal AABB around */
 
  /* the triangle against the AABB */
 
 
 
  /* test in X-direction */
 
  FINDMINMAX(v0[X],v1[X],v2[X],min,max);
 
  if(min>boxhalfsize[X] || max 
 
 
  /* test in Y-direction */
 
  FINDMINMAX(v0[Y],v1[Y],v2[Y],min,max);
 
  if(min>boxhalfsize[Y] || max 
 
 
  /* test in Z-direction */
 
  FINDMINMAX(v0[Z],v1[Z],v2[Z],min,max);
 
  if(min>boxhalfsize[Z] || max 
 
 
  /* Bullet 2: */
 
  /* test if the box intersects the plane of the triangle */
 
  /* compute plane equation of triangle: normal*x+d=0 */
 
  CROSS(normal,e0,e1);
 
  // -NJMP- (line removed here)
 
  if(!planeBoxOverlap(normal,v0,boxhalfsize)) return 0; // -NJMP-
 
 
 
  return 1; /* box and triangle overlaps */
 
}

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Mon, 09 Mar 2009 12:08:22 -0700 CS course 05: Algorithm Design and Analysis (ArsDigita University) (2001) http://blog.jimmyhchan.com/cs-course-05-algorithm-design http://blog.jimmyhchan.com/cs-course-05-algorithm-design Course 05 Algorithm Design and Analysis

 http://www.archive.org/details/arsdigita_05_algorithms

 http://www.archive.org/download/arsdigita_05_algorithms/02-01-01Lect.rm

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan
Mon, 09 Mar 2009 11:49:51 -0700 CS course 01 The Structure and Interpretation of Computer Programs (ArsDigita University) http://blog.jimmyhchan.com/cs-course-01-the-structure-and http://blog.jimmyhchan.com/cs-course-01-the-structure-and http://www.archive.org/details/arsdigita_01_sicp
Course 01: The Structure and Interpretation of Computer Programs
(ArsDigita University) (2000)

 Several courses in Computer Science. This is the first.

  
http://www.archive.org/download/arsdigita_01_sicp/10-02-00Lect.rm

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/42599/jimmy.resized.JPG http://posterous.com/users/1gB3gEbx0CR Jimmy Chan Jimmy Jimmy Chan