Advanced geometry operations in PHP