-1

I'm trying to graph x,y points on a fixed 600x600 pixel JPanel. The origin (0,0) is at the center of the panel (300,300).

I can have points ranging from 0,0 to well into the positive or negative thousands.

How can I scale them so the points farthest from the origin are near the edge of the graph?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Ryan Miles
  • 307
  • 4
  • 11
  • `AffineTransform` preformed on the 'total shape'. Where the 'total shape' is all data points as well as the X/Y scales, legends and labels etc. – Andrew Thompson Dec 16 '14 at 04:25

1 Answers1

2

Find extreme points (the most left one etc) coordinates

MinNegativeX, MinNegativeY, MaxPositiveX, MaxPositiveY 

(for example, -3000, -2000, 1500, 4000)

Define

MaxX = Math.Max(Abs(MinNegativeX), Abs(MaxPositiveX))
MaxY = Math.Max(Abs(MinNegativeYX), Abs(MaxPositiveY))

Then calculate coefficients

CoeffX = 300 / MaxX
CoeffY = 300 / MaxY
Coeff = Math.Max(CoeffX, CoeffY)

Now for every point find new coordinates:

XNew[i] = X[i] * Coeff
YNew[i] = Y[i] * Coeff

(If you want anisotropic scale, just use different coefficients for X and Y)

MBo
  • 77,366
  • 5
  • 53
  • 86