math - Java method Point rot90() -


i trying figure out how implement following method in java;

** point rot90()** query new cartesian point equivalent cartesian point rotated 90 degrees

i have no idea how go creating method. however, believe pulling point (x,y) , outputting new point (y,x*-1) equivalent rotating 90 degrees. old y coordinate becomes nee x coordinate , new y coordinate old x coordinate multiplied negative 1. thoughts on how set method appreciated. thanks.

this have far

  public point rot90(){     point rotated = new point();     rotated.ycoord = xcoord*-1;     rotated.xcoord = ycoord;     return rotated;   } 

i know doesn't work pointed out when try compile it. suggestions?

your method needs argument.

public point rot90(point p){   point rotated = new point();   rotated.ycoord = -p.xcoord;   rotated.xcoord = p.ycoord;   return rotated; } 

if point class has constructor can take coordinates can make shorter.

public point rot90(point p){   return new point(p.ycoord, -p.xcoord); } 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -