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++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -