## Intersection between two circles

December 30th, 2013

I recently had to find the intersection between two circles as part of a robotics related Java programming project. Since I could not find ready made code on the Internet, I used equations from ambrsoft.com to write the appropriate code and things done. See here for complete code. Among other things, finding the intersection points of two circles can be used to resolve the inverse kinematics of a two links robot arm. Assuming the following variables:

• l1: Length of first link
• x0, y0: Coordinates of the point at which the first link is attached.
• l2: Length of second link
• x1, y1: Coordinates of the end effector

The coordinates (x, y) of the point were the two links are joint together (elbow position) can be found by finding the intersection between the two circles with respectively (radius, center x coordinate, center y coordinate): (l1, x0, y0) and (l2, x1, y1).

The angles of the links with respect to the x axis can be found using:

Math.atan2(y1 – y, x1 – x)

Notes:

You should handle the case were there is no solution (the position is not reachable), or there are two solutions, meaning that the position can be reached by positioning the links in two different ways.

I am aware that there are more sophisticated reverse kinematics equations and that this solution is limited to two links and will certainly not handle cases were the links can be oriented in the z dimension. However, who knows, it could help somebody solve a simple problem without resorting to using the big guns.

## KAUST – Growing Pains in the Desert

December 25th, 2012

Interesting article about the problems faced by KAUST at the administrative level: Growing Pains in the Desert.

## Challenged to write a quine

June 22nd, 2012

A what? A quine! What on earth is a quine? Well, a quine is simply a program that takes no input and outputs its own source code. That way, if the output is itself recompiled and executed, it outputs again the original source code. Interestingly, the guy who prompted me to write one in C related the story of a friend of his who was asked to come up with a solution to this problem within one hour during an interview! Under pressure, the guy came up with the solution within 45 minutes, most of which went into thinking, the last 10 minutes of which went into a quick implementation. He was hired. As for the guy telling me the story, he solved it in 65 minutes. It took several hours of thinking and implementation in C (My C skills were relatively rusty since I did not code in this language since 1991). Anyway, I eventually came up with this code after battling to escape a large piece of C code within a string. Note that such an exercise would be trivial in homoiconic languages such as LISP or interestingly in machine language where there is absolutely no difference between data and code (although Executable space protection has somewhat changed the matter).

## Problem installing itunes

June 7th, 2012

There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor.

Solution

Create a folder, say c:\somefolder
Launch the command prompt in administrator more, then issue the following command:
iTunes64Setup.exe /q TARGETDIR=”c:\somefolder”

## Simple Excel Autosave Macro

May 30th, 2012

Private Seconds As Integer

Private Sub Workbook_Open()
Seconds = 300 ‘ 5 minutes. Adjust as you wish
ScheduleSaving
End Sub

Sub ScheduleSaving()
Application.OnTime Now + Seconds / 24 / 3600, “ThisWorkbook.SaveMyWorkbook”, Now + 1.5 * Seconds / 24 / 3600
End Sub

Sub SaveMyWorkbook()
Debug.Print “Saving workbook…”
ThisWorkbook.Save
Debug.Print “Saved workbook.”
ScheduleSaving
End Sub

## Car Accident, King Abdul-Aziz Road, Buraidah, Saudi Arabia, January 7, 2012

January 18th, 2012

A young man aged 24 was killed in a car accident on January 7, 2012 on King Abdulaziz road in the northern city of Buraidah located in the Qassim Region of Saudi Arabia. His Land Cruiser crashed into a light pole located in the road divider near the entrance of the town. The deviated path of the car tend to indicate that the driver was otherwise occupied while driving and lost control as a result. He was transported to Dammam hospital in critical condition where he later died. He never made it to Qassim university where he was to attend a 4th level math exam.

## Car Accident, Dammam-Abqaiq Highway 7, Saudi Arabia, January 7, 2012

January 15th, 2012

## Ubuntu 11.10: I know what you need better than you do

October 23rd, 2011

Failing to get users to voluntarily adopt the Unity desktop manager, Ubuntu is attempting to force adoption by removing the ability to revert to Ubuntu classic interface. Through blogs and forums, the verdict is the same: Unity is a failure. Why is a major Linux distribution like Ubuntu adopting Microsoft tactics to force people into adopting new GUI’s that bring nothing but discontent? Why not solving other usability issues, investing time in improving interoperability with Windows so as to attract new users? Why not addressing other problems that prevent users from moving to Linux? Example: Make sharing a file via SAMBA easier with the authentication integrated with Linux instead of having to play with configuration files.

## Second virtual host under apache 2

September 30th, 2011

After messing around with apache 2 configuration files, I finally finally figured out how to add a virtual host sharing the same IP address and port 80. The confusing part is that multiple config files are involved that might step into each other. The key to understand how these different configuration files work together is to be aware of the following statements in  apache2.conf:

```# Include all the user configurations:
Include httpd.conf
# Include ports listing
Include ports.conf
# Include generic snippets of statements
Include conf.d/
# Include the virtual host configurations:
Include sites-enabled/```

Initially the config files are as follows:

• httpd.conf is essentially empty at installation time
• ports.conf contains some default configuration that applies to the default site
• conf.d is a folder containing module specific configuration files
• sites-enabled is a folder containing virtual host specific configuration files
Notes:
• What you put into these configuration files is more a matter of convention than necessity to get everything working.
• There is another folder called sites-available that contain the configuration files for wannabe virtual hosts. One of these configuration files is default.
• To create a new virtual host
• Copy default into let’s say mynewsite.
• Edit mynewsite and modify modify the folder entries to point to the new site and a line containing “ServerName mynewsite” and save.
• Edit default and add the following lines:
ServerName default
ServerAlias localhost
• Now, the config files in sites-available are not included by apache2.conf. This folder is just there to safeguard your configuration files.
• Copy mynewsite into sites-enabled folder. However, to do that, use “a2ensite mynewsite” (which I assume means apache 2 enable site mynewsite). Behind the scenes, this command has for effect to copy virtual host specific files from sites-available folder to sites-enabled folder. You can disable the new web site by issuing “a2dissite mynewsite”. (apache 2 disable site, I presume).
• Edit /etc/hosts and modify the first line to  “127.0.0.1 localhost mynewsite”. mynewsite should now be ping-able. Restart the apache 2 web server and it should work.
• Create the new site home folder with a index.html file to be able to test that all works OK.
• ## A brief manual on how to use ddrescue

September 12th, 2011

List the available devices, partitions and file systems
sudo fdisk –l
Change current folder to /mnt. Note that you could mount anywhere but traditionally, mounts are done under this folder.
cd /mnt
Create a subfolder under which the USB drive will be mounted. This USB drive will be used to save the hard disk image. Note that you should use sudo in order to issue the commands as admin.
sudo mkdir folder1
Mount the USB drive on the newly created folder. Use the correct file system (ntfs or vfat for FAT32). Get the correct partition name and number from fdisk -l
mount -t ntfs /dev/sdxn /mnt/folder1
Start ddrescue to make an image of the partition into a file called disk.img (you can select any other file name). logfile is used to log the progress. Again, it can be any file name. This will do a first pass on the partition skipping the failed sectors.
ddrescue /dev/sdxn /mnt/folder1/disk.img logfile
Reissue the same command specifying -r 3 to retry the failed sectors three times. You can select a different number of retries.
ddrescue -r 3 /dev/sdxn /mnt/folder1/disk.img logfile
At this point you can reissue the previous command varying the number of retries to attempt further recovery of sectors that have failed so far.
To access the recovered data, you can either mount the image on a Linux system  or copy the disk image into a new hard drive. To mount the image, first create a new mount point (an empty folder under /mnt)
sudo mkdir /mnt/folder2
Mount the image using the loop device that makes the disk image appears as a physical disk
mount -o loop –t ntfs /mnt/folder/disk.img /mnt/folder2
The data can now be accessed by getting into /mnt/folder2 either through the command line or the GUI
To copy the data into a new partition, issue the following command
dd if=/mnt/folder1/disk.img of=/dev/sdxn
where /dev/sdxn refers to the target partition on the new hard drive. Note that this partition should have been created with the exact same size as the original partition. A greater partition than the original would be wasting disk space. Once this is done you can boot Windows and run chkdsk to fix any file system error.
Warning: Issuing dd command with the wrong parameters can destroy your data. Make sure you specify the correct target device after /of=.