Thanks, it's very nice to be appreciated. The model is not complicated, in fact if you look at the KML you'll see three things: -
- Polygons for the grey (Westminster) tower.
- Coloured polygons sampled from a jpeg to make a crude picture of a clock face.
- A dynamic link to the PHP below, which generates the KML for the clock hands on request.
Even the PHP is not too onerous once you look at the part of it that actually does the work.
Thanks - Sid
Code:
<?php
//---------------------------------------------------------
/** Clock class Definition
*/
class AnalogueClock {
var $dFaceLon, $dFaceLat, $dFaceAlt;
var $dHourX, $dHourY;
var $dMinuteX, $dMinuteY;
var $dSecondX, $dSecondY;
var $dHourSize, $dMinuteSize, $dSecondSize;
var $sKml;
var $secondsFrac;
var $minutesFrac;
var $hoursFrac;
//---------------------------------------------------------
/**
*/
function AnalogueClock(){
$this->dFaceLon = 0.1;
$this->dFaceLat = 51.0;
$this->dFaceAlt = 20.0;
$this->dHourSize = 10.0;
$this->dMinuteSize = 10.0;
$this->dSecondSize = 10.0;
$this->sKml = "";
$this->sKml .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$this->sKml .= "<kml xmlns=\"http://earth.google.com/kml/2.0\">\n";
$this->sKml .= "<Folder>\n";
$this->sKml .= "<name>Kreation</name>\n";
$this->sKml .= "<open>1</open>\n";
$timeNow = getdate();
$secondsNow = $timeNow[seconds];
$minutesNow = $timeNow[minutes];
$hoursNow = $timeNow[hours];
if( $hoursNow > 12 )
$hoursNow -= 12;
$this->dSecondsFrac = $secondsNow/60.0;
$this->dMinutesFrac = ((60*$minutesNow) + $secondsNow) / 3600;
$this->dHoursFrac = ((3600*$hoursNow) + (60*$minutesNow) + $secondsNow) / 43200;
}
//---------------------------------------------------------
/** Writes a bit of KML to close the XML
*/
function termKml(){
$this->sKml .= "</Folder>\n</kml>\n";
}
//---------------------------------------------------------
/** Creates KML for a hand - called for each of the hands
*/
function generateHandKml($sPlaceName, $sCol, $dHandSize, $dRadians){
$degreesPerMetre=8.98293242838607E-06;
$dAngle = (3.14159/2)-$dRadians;
$dHoriz = 1.5*$dHandSize * cos($dAngle);
$dVert = $dHandSize * sin($dAngle);
$dHandAlt = $dVert + $this->dFaceAlt;
$dHandLon = $this->dFaceLon + ($dHoriz * $degreesPerMetre);
$dHandLat = $this->dFaceLat;
$this->sKml .= "<Placemark>\n";
$this->sKml .= "<name>" . $sPlaceName . "</name>\n";
$this->sKml .= "<Style>\n";
$this->sKml .= "<LineStyle>\n";
$this->sKml .= "<color>" . $sCol . "</color>\n";
$this->sKml .= "<width>50</width>\n";
$this->sKml .= "</LineStyle>\n";
$this->sKml .= "</Style>\n";
$this->sKml .= "<MultiGeometry>\n<Polygon>\n<tessellate>1</tessellate>\n";
$this->sKml .= "<altitudeMode>relativeToGround</altitudeMode>\n<outerBoundaryIs>\n<LinearRing>\n<coordinates>\n";
$this->sKml .= $this->dFaceLon . "," . $this->dFaceLat . "," . $this->dFaceAlt . " \n";
$this->sKml .= $dHandLon . "," . $dHandLat . "," . $dHandAlt . " \n";
$this->sKml .= "</coordinates>\n</LinearRing>\n</outerBoundaryIs>\n</Polygon>\n</MultiGeometry>\n</Placemark>\n";
}
//---------------------------------------------------------
/** Simple conversion of a 0-1 value to radians
*/
function convertToRadians( $angle){
return 2.0*3.14159 *($angle);
}
}
//---------------------------------------------------------
/** Actual generation of KML
*/
// Set the mime-type to "google earth"
header('Content-type: application/vnd.google-earth.kml+xml');
// Create an instance of a clock
$clock = new AnalogueClock;
// Work out the rotation of each of the hands
$seconds = $clock->convertToRadians( $clock->dSecondsFrac );
$minutes = $clock->convertToRadians( $clock->dMinutesFrac );
$hours = $clock->convertToRadians( $clock->dHoursFrac );
// Generate KML for each hand
$clock->generateHandKml("Hour Hand","#ffff0000", $clock->dHourSize, $hours);
$clock->generateHandKml("Minute Hand","#ff00ff00", $clock->dMinuteSize, $minutes);
$clock->generateHandKml("Second Hand","#ff0000ff", $clock->dSecondSize, $seconds);
// Actually write the KML out and finish
echo "$clock->sKml";
$clock->sKml="";
$clock->termKml();
echo "$clock->sKml";
?>