Anisotropic and Isotropic Mapping Modes

- - - - - - - - - - - - - - - - - - - - - - - -
The term anisotropic mapping implies that the scale factors for x and y are not necessarily equal. Consider the following code fragment: Dimension d = getSize(); int rWidth = 100; int rHeight = 100; int maxX = d.width - 1; maxY = d.height - 1; float pixelWidth = rWidth/maxX; float pixelHeight = rHeight/maxY; ... int iX(float x){return Math.round(x/pixelWidth);} int iY(float y){return Math.round(y/pixelHeight);} float fx(int X){return X * pixelWidth;} float fy(int Y){return (maxY - Y) * pixelHeight;} As you can see, the values of pixelWidth and pixelHeight are a function of the dimensions of the drawing area.

In isotropic mapping, the scale factors for x and y are equal. Further, it is often the case in isotropic mapping mode that the center of the draw area be defined as (0,0). Here's a code fragment which defines coordinates in isotropic mapping mode with the center of the draw area at (0,0).

Dimension d = getSize(); int maxX = d.width -1, maxY = d.height -1; float pixelSize = Math.max(rWidth/maxX, rHeight/maxY); int centerX = maxX/2; int centerY = maxY/2; ... int iX(float x){return Math.round(centerX + x/pixelSize);} int iY(float y){return Math.round(centerY - y/pixelSize);} float fx(int X){return (X - centerX) * pixelSize;} float fy(int Y){return (centerY - Y) * pixelSize;} Here's an applet which uses isotropic mapping mode: import java.awt.*; import java.awt.event.*; import java.applet.*; public class Isotrop extends Applet{ public void init(){ setBackground(Color.white); setLayout(new BorderLayout()); add("Center", new CvIsotrop() ); } } class CvIsotrop extends Canvas{ int centerX, centerY; float pixelSize, rWidth = 10.0F, rHeight = 10.0F, xP = 1000000, yP; CvIsotrop(){ addMouseListener(new MouseAdapter(){ public void mousePressed(MouseEvent me){ xP = fx(me.getX()); yP = fy(me.getY()); repaint(); } }); } void initgr(){ Dimension d = getSize(); int maxX = d.width-1, maxY = d.height-1; pixelSize = Math.max(rWidth/maxX, rHeight/maxY); centerX = maxX/2; centerY = maxY/2; } int iX(float x){return Math.round(centerX + x/pixelSize);} int iY(float y){return Math.round(centerY - y/pixelSize);} float fx(int X){return (X - centerX) * pixelSize;} float fy(int Y){return (centerY - Y) * pixelSize;} public void paint(Graphics g){ initgr(); int left = iX(-rWidth/2), right = iX(rWidth/2), bottom = iY(-rHeight/2), top = iY(rHeight/2), xMiddle = iX(0), yMiddle = iY(0); g.drawLine(xMiddle, bottom, right, yMiddle); g.drawLine(right, yMiddle, xMiddle, top); g.drawLine(xMiddle, top, left, yMiddle); g.drawLine(left, yMiddle, xMiddle, bottom); if(xP != 1000000) g.drawString("Logical coordinates of selected point: " + xP + ", " + yP, 20, 100); } } //<applet code=Isotrop.java width=300 height=300></applet>
- - - - - - - - - - - - - - - - - - - - - - - -
ASSIGNMENT:
Recreate this applet. Supply drawing methods with variables derived from isotropic values only. Click on it to make sure you are fully aware of what it does.