Created
September 20, 2011 12:15
-
-
Save smosher/1228955 to your computer and use it in GitHub Desktop.
basic normal calculation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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