# How to convert LaserScanner msgs to 2D cartesian cooridnates?

I'm trying to convert LaserScanner msgs to 2D vector(cartesian coordinates,(X,Y) pair) in C++ without using any library.Main problem is that I'm using a formula X=r*cos(phi) and Y=r*sin(phi),and if ranges[i] is r,how can I find phi?