Cartesian unit vectors in terms of spherical unit vectors

Here’s a way to express the Cartesian unit vectors \hat x, \hat y and \hat z in terms of \hat r, \hat \phi and \hat \theta where \theta is the zenithal angle and \phi is the azimuthal angle.

We have that \begin{cases}x=r\cos\phi\sin\theta \\y=r\sin\phi\sin\theta\\z=r\cos\theta\end{cases}.

Keeping in mind the definition of the gradient operator: \nabla = (\frac{1}{h_r}\frac{\partial}{\partial r}\hat r + \frac{1}{h_\theta}\frac{\partial }{\partial \theta}\hat \theta+\frac{1}{h_\phi}\frac{\partial}{\partial \phi} \hat \phi) where h_{e_i}=|\frac{\partial \vec r}{\partial e_i}|, so that \nabla =(\frac{\partial}{\partial r}\hat r+ \frac{1}{r}\frac{\partial }{\partial \theta} \hat \theta +\frac{1}{r\sin \theta}\frac{\partial}{\partial \phi}\hat \phi).

The Cartesian unit vectors are simply \hat x = \nabla x =\cos\phi\sin \theta \hat r + \cos\phi\cos\theta\hat\theta-\sin\phi\hat\phi,

\hat y = \nabla y =\sin\phi\sin \theta \hat r + \sin\phi\cos\theta\hat\theta+\cos\phi\hat\phi,

\hat z = \nabla z =\cos \theta \hat r-\sin \theta \hat \theta.

Spherical unit vectors in terms of Cartesian unit vectors

Here’s a way to obtain the spherical unit vectors \hat r, \hat \theta and \hat \phi in terms of the Cartesian unit vectors \hat x, \hat y and \hat z. Note that \theta correspond to the zenithal angle while \phi is the azimuthal angle.

Starting from \begin{cases}x=r\cos\phi\sin\theta \\y=r\sin\phi\sin\theta\\z=r\cos\theta\end{cases}    and \vec r = x \hat x + y \hat y + z\hat z, the spherical unit vectors are given by :

\hat \phi = \frac{1}{h_\phi} \frac{\partial \vec r}{\partial \phi} where h_\phi=|\frac{\partial \vec r}{\partial \phi}|=r\sin \theta is the scale factor. So we have that \hat \phi = \frac{1}{r \sin \theta}(-r\sin \phi \sin \theta \hat x + r \sin \theta \cos \phi \hat y) = - \sin \phi \hat x + \cos \phi \hat y.

While \hat \theta = \frac{1}{r}(r \cos\phi\cos\theta \hat x + r \sin\phi \cos\theta \hat y -r\sin\theta \hat z)=\cos\phi\cos\theta \hat x + \sin\phi \cos\theta \hat y -\sin\theta \hat z;

Finally, \hat r=\frac{\partial \vec r}{\partial r}=\cos\phi\sin\theta \hat x + \sin\phi\sin\theta\hat y +\cos\theta \hat z.

HP pavilion x360 and Linux, dual boot with Windows 8.1 (part 2)

The other problem I faced was reboot/shutdown not working and booting would get stuck approximately once out of three times. The fix is simple and involves disabling two kernel modules: “echo “blacklist dw_dmac” | sudo tee -a /etc/modprobe.d/blacklist.conf” and “echo “blacklist dw_dmac_core | sudo tee -a /etc/modprobe.d/blacklist.conf“. These problems should be gone. Source:

Hope it helps.

Minimum Earth’s angular velocity to which we’d have no weight on a scale

Consider the Earth’s axis of rotation (on itself) as the “z-axis” on a Cartesian coordinate system in which the center of the Earth corresponds to the origin of such a coordinate system. What is the minimum angular velocity or speed of the Earth to which we’d start showing 0 weight on a scale?

The answer depends on the latitude of the considered person. For example the required speed is lesser at the equator than any other place, and is infinite at both poles.

Neglecting the Earth’s motion around the Sun, considering the Earth’s surface as a perfectly spherical and assuming that the mass density inside the Earth has at most a radial dependency (so no dependency on neither the azimuthal nor zenithal angles), any “point” or let’s say “body” (except the 2 poles) on the surface are in circular motion. In such a motion the body is under acceleration, the centripetal acceleration whose magnitude is worth \omega ^2 r where \omega is the angular speed. This acceleration is equal to the gravity’s acceleration g in the case of the critical angular speed of rotation to which the body would start showing no weight on a scale. In such a case we have the relation \omega _{\text{critical}}=\sqrt{\frac{g}{r}} where r is the distance of the body to the axis of rotation. In spherical coordinates, r=R \sin \theta where R stands for the Earth’s radius and theta is the zenithal angle.

Taking g=9.8 \text{ m/s}^2 and R=6367444.7 \text{ m} and considering the equator latitude (theta equal to pi/2), we get \omega_{\text{critical}}\approx 1.24 \times 10 ^{-3} \text{ rad/s} . While the current Earth’s angular speed is roughly worth \frac{2\pi \text{ rad}}{23 \text{ hours } 56 \text{ min}} \approx 7.27 \times 10^{-5} \text{ rad/s} .

From which we get a ratio \frac{\omega_{\text{critical}}}{\omega_{\text{Earth}}} \approx 17. In other words the Earth would have to rotate on itself about 17 times faster than it currently does in order for people to show no weight on a scale at the equator.

Invoke a command to generate a random password of length n

Here’s one way to generate a -good- random password of length n invoking a simple command in the terminal, like so for instance: psswd 30 , where 30 stands for a 30 characters long password.

In order to do so, you need to edit ~/.bashrc or ~/.zshrc depending whether your shell is bash or zsh, and append psswd() { LC_ALL=C tr -dc ‘a-zA-Z0-9-!”@/#$%^&*()_+~’ < /dev/urandom | head -c “$1”;echo ;} to the file, then save it and restart the terminal if you had any opened. Now typing psswd n where n stands for the password length will generate a random password that may contain alphanumerical characters as well as the special characters displayed between the 2 ‘ signs. You can of course modify the characters used to generate the passwords and the function “psswd()” to any of your like.

To finish this blog entry, here’s an example of a 100 characters long password generated by the above command: WTx@X#!O$q!b!IDu+M7gvMVTv-^QK8O-(Y”NMO&%)P1Z4)h2K03uwf(Yc^~h76yi2&CaFE$$R3L&c$XKvnBsojJ6MBgW/S$q-_&o.

Have fun.

Gentoo Linux, compilation of packages’s time

I had heard some complaints that in Gentoo Linux it takes way too much time to compile the packages that one would install in a “normal system”. I got curious and so I gathered this data on my own Gentoo system.

Note that :

  1. My cpu is an Intel Core i3-3217U CPU @ 1.80GHz. (laptop)
  2. As MAKEOPTS value, I have set to use 2 threads for compilation, having HT enabled and so 4 threads in total.
  3. I have 708 packages in total but only 608 of them have been compiled on my machine and so will be used in the data.

Visually the result can be summarized in the following histogram:

gentoo-data Some numbers about time of compilation in seconds (s):

Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
4.0    10.0    20.0   116.9    45.0 20580.0

So in average it took slightly less than 2 minutes to build a package on my system. Most packages take less than 50 s to build and only 3 took more than 1 hour to build (firefox/thunderbird and libreoffice).

Other numbers, about how many times I updated the packages:

Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
1.000   1.000   1.000   1.314   1.000   5.000

In other words most packages were built only once, the average number of times I’ve built a package is 1.314 and the most time I’ve built a package is 5 times.

Considering that I’ve a rather slow processor and “only” 4 GB of RAM, most people could achieve times of building packages up to 5 times lesser easily, I suppose.

Thus overall I’d say that keeping a system up to date in Gentoo doesn’t take too much time, especially on a modern hardware.

P.S.: The bash and R scripts I’ve used to gather and plot the data can be found at and respectively.

HP pavilion x360 and Linux, dual boot with Windows 8.1 (part 1)

I have an HP Pavilion 11-n030ar x360 Notebook (see for the specs) and I faced two major problems when trying to use Linux (any distribution, but let’s say Arch in particular). Thanks to duckduckgo/google I know that other laptop users have faced and will face the same problems so I hope that I can help them.

The first difficulty, assuming you want to install Linux alongside Windows 8.1 in uefi mode, is that the machine will boot Windows 8.1 before anything else, so no way to access Grub or Gummiboot, etc. Well there’s a way that’s cumbersome, it’s to go into the uefi settings from Windows and then pick an option (F9 on my machine) to choose grub, to boot into Linux. But to really install it like it should be, you must go through a hack.

It seems like HP firmware wants to boot Windows no matter what, so the hack consists in renaming a linux.efi file into bootmgfw.efi and move it where the windows efi file is (and replace it) so that HP will boot Grub first, thinking it’s Windows.

I’ll assume from now and on that you have disabled secure boot and fast boot in Windows and that you have installed Linux on your hard drive. Install efibootmgr and grub.

Using the command “efibootmgr -v“, check the path of bootmgfw.efi (that’s the Windows efi file that HP uses to boot the machine) and check the grubx64.efi file from Linux. Now rename bootmgfw.efi into for instance bootmgfw.efiold. With the comandline, to do so you can do: “# mv /path_to_bootmgfw/bootmgfw.efi /path_to_/bootmgfw.efiold“. Now rename the grubx64.efi into bootmgfw.efi and move it to the path where bootmgfw.efiold is. You can do for example “cp path_togrubx64/grubx64.efi path_to_bootmgfw/bootmgfw.efi“. Now a reboot should bring Grub instead of Windows. The problem is that choosing Windows won’t boot it. For it to boot properly you’ll need to create the file /etc/grub.d/40_custom and place in it the part in the file /boot/grub/grub.cfg that refers to Windows (that is, the part that beings with “menuentry ‘Windows …’ which is situated between ### BEGIN (path) ### and ### END (path) ###. Once done, regenerate the grub.cfg file with “# grub-mkconfig -o /boot/grub/grub.cfg“. Now the whole problem should be fixed and you should be able to dual boot with Windows 8.1 normally.


See part 2 to see the other problem I faced.