Cartesian coordinates in Java
I'm trying to draw a function's curve, so I need a method to convert my curve points coordinates to screen coordinates but I can't get it to work. Here's the method I use to convert:
public Poi开发者_如何学Pythonnt tradPoint(Point P){
Point Ptd = new Point();
Ptd.x=getWidth()/2 + P.x*getWidth()/20;
Ptd.y=getHeight()/2 - P.y*getHeight()/20;
return Ptd;
}
but it doesn't work.
I should mention that I'm using a Cartesian coordinate system and a unit=20. Any suggestions?
Thanks
Should be
Ptd.x = getWidth() / 2 + P.x * 20;
Ptd.y = getHeight() / 2 - P.y * 20;
where 20 is the unit width.
Also, Ptd
should be pTd
or even better pointTranslated
and P
should be p
or point
. Java identifiers should start with a lowercase letter and be descriptive.
精彩评论