A sensor device for determining an orientation (α,β,φ,ψ) of a magnet having an axis, the sensor device comprising: a semiconductor substrate comprising a plurality of magnetic sensors configured for determining: i) a first magnetic field gradient (dBx/dx) of a first magnetic field component (Bx) oriented in a first direction parallel to the semiconductor substrate along said first direction; and ii) a second magnetic field gradient (dBy/dy) of a second magnetic field component (By) oriented in a second direction parallel to the semiconductor substrate and perpendicular to the first direction, along said second direction; and iii) a third magnetic field gradient (dBz/dx) of a third magnetic field component (Bz) oriented in a third direction perpendicular to the semiconductor substrate along said first direction; and iv) a fourth magnetic field gradient (dBz/dy) of the third magnetic field component (Bz) oriented in the third direction along said second direction; a processing circuit configured for determining a first angle (α,ψ) based on the first magnetic field gradient (dBx/dx) and the third magnetic field gradient (dBz/dx), wherein the first angle (α,ψ) is formed between a first orthogonal projection of the axis of the magnet on a first virtual plane parallel to the first direction and the third direction, and the first direction or the third direction; and for determining a second angle (β,φ) based on the second magnetic field gradient (dBy/dy) and the fourth magnetic field gradient (dBz/dy), wherein the second angle (β,φ) is formed between a second orthogonal projection of the axis of the magnet on a second virtual plane parallel to the second direction and the third direction, and the second direction or the third direction. a semiconductor substrate comprising a plurality of magnetic sensors configured for determining: i) a first magnetic field gradient (dBx/dx) of a first magnetic field component (Bx) oriented in a first direction parallel to the semiconductor substrate along said first direction; and ii) a second magnetic field gradient (dBy/dy) of a second magnetic field component (By) oriented in a second direction parallel to the semiconductor substrate and perpendicular to the first direction, along said second direction; and iii) a third magnetic field gradient (dBz/dx) of a third magnetic field component (Bz) oriented in a third direction perpendicular to the semiconductor substrate along said first direction; and iv) a fourth magnetic field gradient (dBz/dy) of the third magnetic field component (Bz) oriented in the third direction along said second direction; i) a first magnetic field gradient (dBx/dx) of a first magnetic field component (Bx) oriented in a first direction parallel to the semiconductor substrate along said first direction; and ii) a second magnetic field gradient (dBy/dy) of a second magnetic field component (By) oriented in a second direction parallel to the semiconductor substrate and perpendicular to the first direction, along said second direction; and iii) a third magnetic field gradient (dBz/dx) of a third magnetic field component (Bz) oriented in a third direction perpendicular to the semiconductor substrate along said first direction; and iv) a fourth magnetic field gradient (dBz/dy) of the third magnetic field component (Bz) oriented in the third direction along said second direction; a processing circuit configured for determining a first angle (α,ψ) based on the first magnetic field gradient (dBx/dx) and the third magnetic field gradient (dBz/dx), wherein the first angle (α,ψ) is formed between a first orthogonal projection of the axis of the magnet on a first virtual plane parallel to the first direction and the third direction, and the first direction or the third direction; and for determining a second angle (β,φ) based on the second magnetic field gradient (dBy/dy) and the fourth magnetic field gradient (dBz/dy), wherein the second angle (β,φ) is formed between a second orthogonal projection of the axis of the magnet on a second virtual plane parallel to the second direction and the third direction, and the second direction or the third direction.