Pankaj Mehra
Pankaj Mehra

Reputation: 134

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

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

Upvotes: 5

Views: 4185

Answers (3)

Farzad Khalafi
Farzad Khalafi

Reputation: 309

look up canvas.scale(xs,ys,xp,yp)

xp and yp are the new coordinates that you set for your (0,0) point.

Upvotes: 0

Steve Blackwell
Steve Blackwell

Reputation: 5924

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.

Upvotes: 2

Bill Mote
Bill Mote

Reputation: 12823

I don't know that you're going to have much luck changing where (0,0) is located, but you could set a constant that accounts for such. myY = y minus screenHeight so (x, myY) adjusts y to the bottom of the screen and works from there +/-.

Upvotes: 0

Related Questions