updated code to be much more efficient (less triangle area calculation)