Donnerstag, 28. Januar 2010

R - Open Source Statistics

[Intro Article.. R pretty much rocks. www.r-project.org , needs better GUI. ]

Basic Matlab Function Equivalents:

Matlab RDescription
ones(n,m)*a mat.or.vec(n,m)*a initialize matrix with values
rand(m)runif(n,min,max)n float random numbers between min&max.
  sample(min:max,n)picks n elements of the data given as first argument (i.e. integers!)
reshape(a,[n,m..])matrix(a,nrow=n,ncol=m)reshape data structure into a matrix
for i=1:30
    op(i);
end
for (i in 1:30); {
    op(i);
}
for loop!
function [x y z] = uvw(a,b,c=3)
    op(a,b,c);
end
uvw<-function(a,b,c=3) {
    op(a,b,c);
}
function definition 
a = [];a <- matrix(nrows=0,ncols=3)how to init a matrix to be grown dynamically
a = [b;c;d];a <- rbind(b,c)concatenate matrix vertically
a = [b,c,d];a <- cbind(b,c,d)concatenate matrix horizontally
......

Freitag, 15. Januar 2010

Google Earth: Move Camera to certain Viewpoint

Problem:
How do I move the camera to a certain viewpoint, given as [world coordinates, height, azimuth and elevation] in Google Earth?

I recently had to re-stage some perspective aerial photos, knowing the location and height of the plane, as well as the viewing direction. Unfortunately, the Google Earth (5.0) UI does not seem to offer a possibilty to just enter those viewpoint parameters.
Now, the trick is to use placemarks: set a placemark somewhere and open its properties dialog.
In this dialog, we can enter the exact coordinates, azimuth and elevation. So far so good, but it's not yet perfect:
We can also specify the height in this dialog, but this will only move the placemark up in the air - not our viewpoint! The camera will always hover around the projection of the placemark on the ground level. But again there is a dodge to get this working:
Save your viewpoint as KML (plaintext), and open it with a text editor. You will see the xml-structure of the KML file, containing all the information about our placemark including the viewing direction:


<?xml version="1.0" encoding="UTF-8"?>
<kml ...>
<Document>
    <name>aerialviewpoint.kml</name>
    <Placemark>
        <name>my point in the air</name>
        <open>1</open>
        <LookAt>
            <longitude>8.765</longitude>
            <latitude>47.474</latitude>
            <altitude>1000</altitude>
            <range>1</range>
            <tilt>85</tilt>
            <heading>120</heading>
            <altitudeMode>absolute</altitudeMode>
        </LookAt>
        <Point>
            <extrude>1</extrude>
            <altitudeMode>absolute</altitudeMode>
            <coordinates>8.765,47.474,1000</coordinates>
        </Point>
    </Placemark>
</Document>
</kml>

Here we can change the height of the viewpoint (field altitute in the -Tag) to our desired height. Then save and reopen the KML file with Google Earth, where we will fly directly to this viewpoint. []