Archive for January, 2012

serendipity on the walls of the musée d’art et d’histoire

Monday, January 30th, 2012

mosset

modernity in japan

Monday, January 30th, 2012

modernity in japan

http://alecjacobson.com/art/digital/
http://alecjacobson.com/art/

intrinsic cotangent formula

Monday, January 23rd, 2012

Here’s a derivation of the cotangent of an angle α of a triangle ABC given just the lengths of each side of the triangle.
acute triangle

First of all we remind ourselves what cotangent is in terms of cosine and sine:


        cos α
cot α = ------
        sin α

Now look at cosine and sine separately. By the law of cosines we have that


a2 = b2 + c2 - 2bc cos α

Rearranging things we have that


        -a2 + b2 + c2
cos α = ------------
             2bc

Now looking at the sine, we start with the familiar area of the triangle treating b as the base.


     1
A = --- bh
     2

Using SOH-CAH-TOA, we replace the height:


     1
A = --- bc sin α
     2

Rearranging this we have:


         2A
sin α = ----
         bc

Now put the cosine and sine derivations together to get:


        cos α    -a2 + b2 + c2   bc
cot α = ------ = ------------  ----
        sin α        2bc        2A

Finally arriving at:


        -a2 + b2 + c2
cot α = ------------
             4A

hdlr

Monday, January 23rd, 2012

hdlr

http://alecjacobson.com/art/digital/
http://alecjacobson.com/art/

Shuffle rows of a matlab matrix

Sunday, January 15th, 2012

Neat little trick using the keyword end:


M =  M(randperm(end),:);

Matlab colorbar without ticks

Sunday, January 15th, 2012

Took a me a little bit to figure out how to make a color bar in matlab without tick marks.


hcb=colorbar;
set(hcb,'YTick',[])

Display wireframe mesh in matlab and save as vector graphics

Saturday, January 14th, 2012

For our siggraph submission I wanted to overlay a 2D image with the wireframe of the mesh we use to deform it. In matlab I can display a 2D mesh (V,F) easily using:


trisurf(F,V(:,1),V(:,2),0*V(:,1));
view(2);
axis equal;

If I save this as .eps then I get a nice vector graphics version of my mesh.

But if I don’t want the filled faces to show up in the vector output, then when I try to save the following figure as a .eps file:


trisurf(F,V(:,1),V(:,2),0*V(:,1),'FaceAlpha',0);
view(2);
axis equal;

matlab just pretends to make a postscript vector file but instead its just a .eps file containing a raster image.

Here’s what I do to get a .eps vector graphics postscript file (which can then be turned into a PDF since output to PDF is broken in matlab):


E = edges(F);
plot([V(E(:,1),1) V(E(:,2),1)]',[V(E(:,1),2) V(E(:,2),2)]','k-');
view(2);
axis equal
set(gcf, 'Color', [1,1,1]);
set(gca, 'visible', 'off');

complimented by spam, complemented by spam

Tuesday, January 10th, 2012

complimented
                by spam
complemented

Screen capture a remote desktop into the remote clipboard

Friday, January 6th, 2012

I’m working a bit with Apple Remote Desktop now and I’m having trouble taking screen captures. It seems easy to take a screen capture that ends up as a file on or in the clipboard of the client side. But I’d rather be completely immersed in the remote computer, so ideally when I hit CMD+SHIFT+3 I’d get a screen shot the size and resolution of my remote desktop saved to the remote’s clipboard.

Here’s what I’m doing for now. I prepare my app that I want to screen capture then I switch to terminal and issue


echo "tell application \"skinning\" to activate" | osascript - && screencapture -c

This switches to my app and takes a screen capture into the clipboard.

Patch for AntTweakBar to support pasting from clipboard on Mac OS X

Tuesday, January 3rd, 2012

I recently noticed I could use pbpaste and a system call to integrate the clipboard’s contents into my C++ programs. I use AntTweakBar all the time for quick prototyping UI and though it has a default internal clipboard, I found it frustrating that it doesn’t hook into my mac’s global clipboard. To make this happen I just modified TwBar.cpp in two places EditInPlaceSetClipboard and EditInPlaceGetClipboard, surrounding each edit with #elif defined ANT_OSX. Now I can copy from my AntTweakBar and paste into some other app or copy from some other app and paste into an AntTweakBar string field.

Here’s what to place in EditInPlaceSetClipboard

// PATCH BEGIN Alec Jacobson, 2012
// PATCH BEGIN Alec Jacobson, 2012
#elif defined ANT_OSX
    stringstream cmd;
    cmd << "echo \"" << _String << "\" | pbcopy";
    FILE* pipe = popen(cmd.str().c_str(), "r");
    if (!pipe)
    {
        return false;
    }
// PATCH END

And here’s what to place in EditInPlaceGetClipboard

// PATCH BEGIN Alec Jacobson, 2012
// PATCH BEGIN Alec Jacobson, 2012                                                                        
#elif defined ANT_OSX
    FILE* pipe = popen("pbpaste", "r");                                                                   
    if (!pipe)
    {   
        return false;
    }                                                                                                     
    char buffer[128];
    string result = "";                                                                                   
    while(!feof(pipe))
    {   
        if(fgets(buffer, 128, pipe) != NULL)                                                              
        {
            result += buffer;                                                                             
        }                                                                                                 
    }   
    pclose(pipe);
    *_OutString = result.c_str();                                                                         
// PATCH END

To ensure your binaries run with this patched version you might consider compiling AntTweakBar as a static library.