2D proportional point plots

Started by
0 comments, last by Buckeye 13 years, 1 month ago
Hi,

I have a set of 2D points to plot. Each set can contain any range of values. The bounds of my window can be resized to change also.

My problem is that I can't find a formula that will proportionally plot my points in the canvas space correctly no matter what the window size or range of values are.

Can anyone help w/ this formula?

Advertisement
Determine the minimum and maximum X values and Y values of your 2D points. Calculate 2 ratios like so:

float xratio = float(windowWidth)/(pt2DmaxX - pt2DminX);
float yratio = float(windowHeight)/(pt2DmaxY - pt2DminY);

// plot each point pt( x, y )
int windowX = int( (pt.x - pt2DminX) * xratio );
int windowY = int( (pt.y - pt2DminY) * yratio );


That's off the top of my head so look it over.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement