Matlab POLYBOOL: external contours and internal contours

The Matlab Mapping Toolbox allows one to perform several useful arithmetic operations with polygons, including finding the intersection (POLYBOOL) and areas (POLYAREA) of polygons.

A warning message you may see when working with POLYBOOL is
Warning: (X1,Y1) contains no external contours. Function POLYBOOL assumes that that external contours have
clockwise-ordered vertices, and all contours in (X1,Y1) have counterclockwise-ordered vertices. Use POLY2CW
to reverse the vertex order if necessary.

Here is what Matlab means by “external contours” and “internal contours”.

External contour: the vertices describing the outer edge of a polygon–the outside of a donut, for example. These vertices must be given in CLOCKWISE order.

Internal contour: the vertices describing an area in which the convex hull is hollow (the donut hole). These vertices must be given in COUNTERclockwise order.


Intel AMT / vPro full remote KVM control without proprietary RealVNC Viewer Plus

Here is how to have full remote KVM control of your PC without the proprietary RealVNC Viewer Plus software.

Note: if you already have PCs in the field without these changes, you can change the settings remotely–but as always, exercise great care, as a wrong checkbox hit can necessitate a field trip to the PC to correct–in my case, it might be thousands of miles and a dog sled ride away!!

  1. Download the free, open-source Intel Open Manageability Toolkit to your local (home office) PC and install it on your home office PC
  2. Open the “Manageability Commander Tool” and click File > Add > Add Intel AMT computer and type the IP address and vPro username (typically “admin”) and password (you will have had to have set this up previously)
  3. Click the little plus sign by Network and click on your AMT PC’s name–then in the Connection tab, click Connect. This will take about 5-10 seconds to connect–if UNsuccessful, the button will fall back to saying Connect. If successful, the button will change to say Disconnect.
  4. Go to the Remote Control tab and wait about 10 seconds for the “remote desktop” items to change from “unknown” to the actual state. If Remote Desktop Settings is “Disabled”, click the little box to its right to open a new window. Change the settings to look as follows–note, for Strong Password, it must be exactly 8 characters, including at least one number, one symbol, and one capital letter. (actually that’s a pretty weak password, but it’s Intel’s choice..)
  5. Click OK and then go back to the Connection tab and click Disconnect. Don’t mess around with any of the other settings unless you know exactly what you’re doing and are willing to drive out to the remote PC to fix it if you mess something up!  Close the Manageability Commander program.
  6. Now you should be able to connect using a standard VNC program. You’ll notice I used “localhost” since I SSH into the remote PC first–DO NOT expose this VNC port 5900 to the internet or you are likely to get hacked!

If you use a Windows PC to connect, note that you can use Cygwin at one or both ends to create an SSH server and/or client necessary for secure port forwarding. Please use SSH public key authentication as it is vast orders of magnitude more secure than keyboard passwords.

C++: writing code to work in both Visual Studio (windows) and g++ (linux)

This is written for someone looking to quickly write some code in C/C++ for mathematical computations.

You might be used to using Visual Studio in Windows instead of the Code::Blocks or Eclipse-CDT available on Windows/Mac/Linux.

Here are a few things to consider to compile your Visual Studio-originated C++ under multi-platform (Windows Mac Linux)

* Command line compilation
I start out by compiling with the command line so that I feel I know what options are being used to compile–so that if I send my code to a friend, they can compile it too.

In Linux for C++ you would compile with EITHER the LLVM-Clang or G++ toolkit (your choice–LLVM-Clang is more modern and is what I use)

Example LLVM-Clang compile command:
clang++ -o foo -std=c++11 foo.cpp -lncurses -lm

Example G++ compile command:

g++ -o foo -std=c++11 foo.cpp -lncurses -lm

Then type <code>./foo</code> to run your program.

* Environment conditionals
Here we modify the “include” part of our code to be appropriate for the operating system we’re compiling for. Let’s assume the original Windows Visual Studio code had
#include <conio.h>

In Linux, we use ncurses instead. So modify to:

#ifdef _WIN32
#include "stdafx.h"
#include <conio.h>
#else // LINUX MAC
#include <ncurses.h>

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <math.h>

note the “#include “stdafx.h”” is a file used by Visual Studio to set compilation preferences.

remember the “-lncurses” and “-lm” we typed to compile? This tells the compiler to link to math.h and ncurses.h (I assumed you would be using math functions and outputing text to the console).

* writing files

Since we included “fstream” we can write files to disk.  But Windows and Mac/Linux use different directory slashes.  Windows uses backslashes \   and Mac/Linux uses forward slashes /


Windows 8.1 on Virtualbox 4.2

You will need to have at least VirtualBox version 4.2.16, or you will get error like:
Windows 8.1 preview installation fails: Your PC needs to restart | Please hold down the power button | Error Code 0x000000C4

And when setting up the VM, be sure to select Windows 8.1, not just Windows 8 !

Also, I recommend to select a “Fixed”, NOT “dynamic” hard drive for Windows 8, as the disk performance is quite slow when using Dynamic sized HDD. (this is also true for Windows XP & Windows 7, but moreso for Windows 8 )

Greek Fonts in Draftsight

Draftsight V1R3.2 doesn’t currently allow the <ctrl><shift>u trick that works for most other Ubuntu program to get Greek characters.

However, Draftsight V1R3.2 does have the ARGrekS.shx font, which has many Greek symbols.

in DraftSight, type style and under Drafting Styles>Text create a new style called “greek” and select font “ARGrekS.shx” and then under Drafting Styles>Dimension create a new style that uses this font style you just made.

Google Earth 7.1 crash fix (Ubuntu 13.04 x64)

Many have reported problems with Google Earth 7.1 under Ubuntu (as of July 2013). An strace of google-earth was not very revealing.

I noticed that I had installed the 64-bit .deb package from the Google website–this version crashes when typing a search query into the Google Earth search box.

To remedy this (for my PC at least) here’s what I did.

1) Uninstalled Google Earth 7.1 64-bit by typing in Terminal
sudo dpkg -r google-earth-stable
2) Delete the entire ~/.googleearth directory
3) download the 32-bit .deb package from Google and install

Then I could make searches without Google Earth 7.1 crashing.

Canon ImageClass MF4350d: using as a scanner under Ubuntu 64-bit

Once you have installed the printer drivers, you can also setup your Canon MF4350d (and probably other Canon multifunction devices) under Ubuntu 64-bit 12.04 LTS, etc.

1) sudo apt-get install xsane
2) start xsane and it will automatically scan for connected scanners. You should see the name of your scanner in the titlebar of each xsane window in a few seconds.

You can send faxes using Xsane as well.

Canon ImageClass MF4350d: Ubuntu 64-bit driver install

Note: I no longer use this printer; I have switched to using Brother printers, since their Linux support is FAR better. So I am unable to provide further insights on the MF4350d on Linux at this time, sorry.


In summer 2013, the 64-bit Debian/Ubuntu drivers finally came out for the Canon MF4350d multi-function printer (as well as a whole host of other Canon printers). Previously, a lot of wrangling was seen on the web using tricks like the “alien” program to bring the RPM files to Ubuntu.

All this fuss is no longer necessary–the drivers are available from:

Procedure (simple) for Ubuntu 64-bit 12.04 LTS:
1) Download drivers from URL above (in a tar.gz archive)
2) extract archive to convenient location (you can delete them when done installing) say, /tmp
Then type in Terminal:

cd /tmp/Linux_UFRII_PrinterDriver*/64*/Debian/
sudo dpkg -i cndrvcups-common*amd64.deb
sudo dpkg -i cndrvcups-ufr2*amd64.deb

3)Now open your Web browser and type localhost:631
4) click Administration, Add Printer, and type your Ubuntu username and password
5) under “local printers” select “Canon MF4320-4350 (UFRII LT) CNUSB #1 (Canon MF4320-4350 (UFRII LT))” and click Continue
6) you can type whatever name you might want “Front office Printer” or whatever or just leave it alone and click continue
7) Under “model” find your model of printer (there are a ton of them listed, check the whole list!) and click Add Printer

Now you can print a test document to verify it works. Up next, an article on how to use the scanner feature of the MF4350d!

The Canon MF4350d is a nice multifunction device that now works very well with Ubuntu Linux. Both the scanner and the printer features work great–and rather inexpensive toner is available from third parties on Amazon and eBay. The main downsides of the MF4350d vs. more expensive MFC’s are:
1) document scanner is SINGLE-sided instead of double-sided
2) the “d” model does not have Ethernet (the MF4370dn is networked, but I have not used that model).

Ubuntu/Linux DOSBOX: setting up USB to Serial RS232 port convertor

Here’s how to setup a USB to serial convertor to use with DOSBOX on Linux:

1) type ll /dev/ttyUSB* and note the device corresponding to your USB to serial adapter (probably /dev/ttyUSB0 unless you have multiple such adapters)
2) type sudo chmod 666 /dev/ttyUSB0 (assuming ttyUSB0 is your device)
3) Edit the DOSBOX configuration file by typing gedit ~/.dosbox/dosbox*.conf
4) find the [serial] portion of dosbox.conf file in gedit, and modify the serial1=dummy to be:
serial1=directserial realport:ttyUSB0
5) run DOSBOX and you should find your serial device on COM1

Matlab R2013a: Testing C++ MEX on Ubuntu 64-bit

To use C++ MEX for Matlab R2013a on Ubuntu 13.04, you must first have setup GCC 4.4 as described in:

(1) Copy and paste the following text into your Matlab Command Window:

copyfile(fullfile(matlabroot,'extern','examples','mex','yprime.c'), '~')
mex yprime.c

(2) test by typing in Matlab command window:


ans =

2.0000 5.9924 1.0000 2.986