Changing position of a button

You have to get a reference to you button, for example by calling findViewById(). When you got the reference to the button you can set the x and y value with button.setX() and button.setY(). …. Button myButton = (Button) findViewById(R.id.<id of the button in the layout xml file>); myButton.setX(<x value>); myButton.setY(<y value>); ….

Transforming accelerometer’s data from device’s coordinates to real world coordinates

Oki, I have worked this out mathematically myself so please bear with me. If you want to translate an acceleration vector accelerationvalues into an acceleration vector trueacceleration expressed in real world’s coordinates, once you have azimuth,pitch and roll stored in a orientationvalues vector, just do the following: trueacceleration[0] =(float) (accelerometervalues[0]*(Math.cos(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.sin(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[1]*(Math.cos(orientationvalues[1])*Math.sin(orientationvalues[0])) + accelerometervalues[2]*(-Math.sin(orientationvalues[2])*Math.cos(orientationvalues[0])+Math.cos(orientationvalues[2])*Math.sin(orientationvalues[1])*Math.sin(orientationvalues[0]))); trueacceleration[1] … Read more

Getting the coordinates from the location I touch the touchscreen

In a UIResponder subclass, such as UIView: override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.anyObject()! as UITouch let location = touch.locationInView(self) } This will return a CGPoint in view coordinates. Updated with Swift 3 syntax override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.first! let location = touch.location(in: … Read more

How to perform bilinear interpolation in Python

Here’s a reusable function you can use. It includes doctests and data validation: def bilinear_interpolation(x, y, points): ”’Interpolate (x,y) from values associated with four points. The four points are a list of four triplets: (x, y, value). The four points can be in any order. They should form a rectangle. >>> bilinear_interpolation(12, 5.5, … [(10, … Read more