density calculation function complete