views:

58

answers:

1

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 Point 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

+2  A: 

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.

Skip Head
thanks a lot,but that didnt work maybe the unit width im taking is wrong , is there another way ?
Mona
@Mona: In what way did this not work?
Troubadour
@Mona: This should work. Maybe there's another problem? What results are you getting for what inputs?
Skip Head
thanks a lot , problem was my unit width shouldnt be 20.
Mona