Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This file contains a class for you to extend with your solution.
- function MeasurementAppController()
- {
- var self = this;
- var cameraVideoPageController = null;
- this.cameraVideoPageInitialised = function(controller)
- {
- cameraVideoPageController = controller;
- var self=this
- //BUTTONS
- var height =
- {title: "Set camera height", onClick: "measurementAppController.height()"}
- var topAngle =
- {title: "Angle to apex", onClick: "measurementAppController.topAngle()"}
- var bottomAngle =
- {title: "Angle to base", onClick: "measurementAppController.bottomAngle()"}
- var distanceAndHeight =
- {title: "Calculate distance + height", onClick: "measurementAppController.distanceAndHeight()"}
- var buttons = [height, topAngle, bottomAngle, distanceAndHeight]
- cameraVideoPageController.addButtons(buttons)
- setInterval(function() {cameraVideoPageController.setHeadsUpDisplayHTML("angle: " + betaValue.toFixed(0) + '°')}, 0) //this function is called continously so the angle of the phone can always be seen
- }
- //FUNCTIONS
- this.height = function ()
- {
- var self=this
- this.setHeight=prompt("Please enter your approximate height(m)")
- }
- //SET THE TOP ANGLE
- this.topAngle = function() //set the top angle
- {
- var self=this
- this.setTopAngle = betaValue.toFixed(0)
- if (this.setTopAngle < 180 && this.setTopAngle > 0) // the top angle must be between these specifications
- {
- cameraVideoPageController.displayMessage("The angle to the object's APEX is set as " + this.setTopAngle + '°')//pops up little window notifying the user they have set the angle
- }
- else // picks up any errors
- {
- alert ("Please set an angle to the apex between 0° and 180°")
- }
- }
- //SET THE BOTTOM ANGLE
- this.bottomAngle = function() //set the bottom angle
- {
- var self=this
- this.setBottomAngle =betaValue.toFixed(0) // rounds to nearest degree so values aren't so jumpy
- if (this.setBottomAngle < 90 && this.setBottomAngle > 0) // the bottom angle must be below 90 degrees or else it is impossible to calculate
- {
- cameraVideoPageController.displayMessage("The angle to the object's BASE is set as " + this.setBottomAngle + '°') //pops up little window notifying the user they have set the angle
- }
- else // picks up any errors if angle is not <90 degrees
- {
- alert ("Please set an angle to the base between 0° and 90°")
- }
- }
- //SET THE DISTANCE AND HEIGHT
- this.distanceAndHeight = function() //calculate distance and height
- {
- var self=this
- if (this.setTopAngle > 90 && this.setTopAngle<180 && this.setBottomAngle <90 && this.setBottomAngle > 0) //forumla for calculating distance + height if apex is above camera height
- {
- this.distance = this.setHeight*Math.tan(this.convert(this.setBottomAngle))
- this.totalHeight = this.setHeight*(1 + (Math.tan(this.convert(this.setTopAngle-90))/Math.tan(this.convert(90-this.setBottomAngle)))) //formula for calculating height --> i did it all in one step as i thought it would get too messy and complicated if i created seperate functions
- alert("The object is " + this.distance.toFixed(2) + " metres away and it is " + this.totalHeight.toFixed(2) + "metres high") //popup window of the values
- }
- else if (this.setTopAngle > 0 && this.setTopAngle < 90 && this.setBottomAngle <90 && this.setBottomAngle > 0) //forumla for calculating distance + height if apex is below camera height
- { this.distance = this.setHeight*Math.tan(this.convert(this.setBottomAngle)) //forumla for calculating distance
- this.totalHeight = this.setHeight - (this.distance/Math.tan(this.convert(this.setTopAngle)))
- alert("The object is " + this.distance.toFixed(2) + " metres away and it is " + this.totalHeight.toFixed(2) + "metres high") //popup window of the value
- }
- else
- {
- alert ("Unable to calculate distance + height!") //picks up any errors
- }
- }
- //CONVERT DEGREES TO RADIANS
- this.convert = function(x)
- {
- return Math.PI/180 * x
- }
- }
- // OTHER METHODS
- //get Beta Value
- function handleOrientation(event)
- {
- var self=this
- this.betaValue= event.beta;
- }
- window.addEventListener("deviceorientation", handleOrientation, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement