Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android screen coordinate system : how to set (0,0) at the bottom left side of android screen as first quadrent of xy plane

Tags:

android

how to set the screen coordinate system of android screen as first Quadrant of the XY plane ,iwant the (0,0) position to be at bottom left , and i wanna know if i can use the trignometric equation on android screen as Android XY plane is not like the Xy plane

like image 917
Pankaj Mehra Avatar asked Nov 05 '22 01:11

Pankaj Mehra


1 Answers

I don't think there's a way to do it that would affect the entire system, such as the XML layout files. But if you just want to draw with a Canvas, you can use translate() and scale().

First use translate() to slide the canvas down so 0,0 is at the bottom. Now the top of the screen would be a negative number, so call scale() to flip it around. Now 0,0 is still at the bottom, and the top of the screen is a positive number.

I'm working with information from this answer and its comments. Use something like:

canvas.save();                            // need to restore after drawing
canvas.translate(0, canvas.getHeight());  // reset where 0,0 is located
canvas.scale(1, -1);                      // invert
...                                       // draw to canvas here
canvas.restore();                         // restore to normal

And yes, you can use normal 2D trigonometric functions with the XY coords. You can do it even if they're not translated, you just have to think it through more carefully.

like image 65
Steve Blackwell Avatar answered Nov 11 '22 12:11

Steve Blackwell