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?
2D proportional point plots
Determine the minimum and maximum X values and Y values of your 2D points. Calculate 2 ratios like so:
That's off the top of my head so look it over.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement