Sunteți pe pagina 1din 3

// The CameraVideoPageController is a class that controls the camera

// video page. This class provides a some useful methods you will
// need to call:
//
cameraVideoPage.displayMessage(message, timeout):
//
Causes a short message string to be displayed on the
//
page for a brief period. Useful for showing quick
//
notifications to the user. message is a plain string.
//
timeout is option and denotes the length of time in msec
//
to show the message for.
//
cameraVideoPage.setHeadsUpDisplayHTML(html):
//
This will set or update the heads-up-display with the
//
text given in the html argument. Usually this should
//
just be a string with text and line breaks (<br />).
// Initialise the camera video page and callback to our
// cameraVideoPageInitialised() function when ready.

//Beta Value from the


var cameraVideoPage = new CameraVideoPageController(
cameraVideoPageInitialised);
var cameraHeight = 0;
var beta = 0;
var beta3 = 0;
var betavalue = 0;
var BaseAngle = 0;
var ApexAngle = 0;
var Distance = 0;
var Height = 0;
var array = [];
function handleOrientation(event) {
var beta1 = event.beta.toFixed(1);
var beta2 = +beta1;
array.push(beta2);
if(array.length = 11)
{
array.shift();
}
beta3 = avg(array).toFixed(1);
//Display
cameraVideoPage.setHeadsUpDisplayHTML("angle:"+ beta3 + "<br/>" + "Camer
a Height(m): " + cameraHeight + "<br/>"+"Base Angle(degree): " + BaseAngle + "<b
r/>"+"Apex Angle(degree): " + ApexAngle + "<br/>"+"Distance(m): " + Distance.toF
ixed(2) + "<br/>"+"Height(m): " + Height.toFixed(2) + "<br/>");
// Do stuff with the new orientation data
}
function avg(array)
{
var sum = 0;
for (var j = 0; j <array.length ; j++)
{
sum += array[j];
}

return sum / array.length;


}
var betaRadian = toRadians(beta3);
function toRadians (angle) {
return angle * (Math.PI / 180);
}

// You may need to create variables to store state.


// This function will be called when the camera video page
// is intialised and ready to be used.
function cameraVideoPageInitialised()
{
window.addEventListener("deviceorientation", handleOrientation, true); // Ste
p 1: Check for and intialise deviceMotion
}
// This function is called by a button to set the height of phone from the
// ground, in metres.
function setCameraHeightValue()
{
// Step 3: Set camera height
// check if input is a number and is positive
// display on screen using the displayMessage method
cameraHeight = prompt("Set camera height: (m)","1.8");
// check if input is a number and is positive
if (isNaN(cameraHeight) === false && cameraHeight > 0)
{
// display on screen using the displayMessage method
cameraVideoPage.displayMessage("Camera Height(m): " + cameraHeight);
}
else
{
cameraVideoPage.displayMessage("Invaild number!!");
}
}
// This function is called by a button to set the angle to the base of
// the object being measured. It uses the current smoothed tilt angle.
function setBaseTiltAngle()
{
BaseAngle = beta3;// Step 4: Record tilt angle
// display on screen using the displayMessage method
var BaseAngleRad = toRadians(BaseAngle);
distance(BaseAngleRad,cameraHeight);
cameraVideoPage.displayMessage("Base Angle(degree): "+ BaseAngle);
}
// This function is called by a button to set the angle to the apex of
// the object being measured. It uses the current smoothed tilt angle.
function setApexTiltAngle()
{

ApexAngle = beta3;
var Theta = ApexAngle - 90;
// Step 4: Record tilt angle
// display on screen using the displayMessage method
ThetaRad = toRadians(Theta);
height(ThetaRad,cameraHeight,Distance);
cameraVideoPage.displayMessage("Apex Angle(degree): " + ApexAngle);
}
//Distance
function distance(angle,CameraHeight)
{
Distance = cameraHeight * Math.tan(angle);
};

//Height
function height(angle,CameraHeight,distance)
{
Height = +CameraHeight + distance*(Math.tan(angle - Math.PI));
}

S-ar putea să vă placă și