Skip to content

Instantly share code, notes, and snippets.

@smosher
Created September 20, 2011 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smosher/1228955 to your computer and use it in GitHub Desktop.
Save smosher/1228955 to your computer and use it in GitHub Desktop.
basic normal calculation
sub vector-to-unit( @vec ) { @vec >>/>> sqrt( [+] @vec >>**>> 2 ) }
sub cross-product( @v1, @v2 ) {
( @v1[1,2,0] >>*<< @v2[2,0,1] )
>>-<<
( @v1[2,0,1] >>*<< @v2[1,2,0] )
}
sub surface-to-normal( @a, @b, @c ) {
my @b2 = @b >>-<< @a;
my @c2 = @c >>-<< @a;
my @normal = cross-product( @b2, @c2 );
return vector-to-unit( @normal ); # what's a normal if it's not actually normal?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment