@@ -0,0 +1,2493 @@
+//%0A// $Id: WhichSideViz.java,v 1.1 2002/06/28 01:29:32 mdb Exp $%0A%0Apackage com.threerings.geom;%0A%0Aimport java.awt.BorderLayout;%0Aimport java.awt.Color;%0Aimport java.awt.Graphics;%0Aimport java.awt.Point;%0A%0Aimport java.awt.event.MouseEvent;%0Aimport java.awt.event.MouseMotionListener;%0A%0Aimport javax.swing.JFrame;%0Aimport javax.swing.JPanel;%0A%0Aimport com.samskivert.swing.util.SwingUtil;%0A%0A/**%0A * Renders the nearest point on a line just for kicks.%0A */%0Apublic class WhichSideViz extends JPanel%0A    implements MouseMotionListener%0A%7B%0A    public WhichSideViz ()%0A    %7B%0A        addMouseMotionListener(this);%0A    %7D%0A%0A    public void doLayout ()%0A    %7B%0A        super.doLayout();%0A        _center = new Point(getWidth() / 2, getHeight() / 2);%0A    %7D%0A%0A    public void paintComponent (Graphics g)%0A    %7B%0A        super.paintComponent(g);%0A%0A        int dx = (int)Math.round(Math.cos(_theta) * 200);%0A        int dy = (int)Math.round(Math.sin(_theta) * 200);%0A%0A        g.setColor(Color.blue);%0A        g.drawLine(_center.x, _center.y, _center.x + dx, _center.y + dy);%0A        g.setColor(Color.white);%0A        g.drawLine(_center.x, _center.y, _center.x - dx, _center.y - dy);%0A%0A        int nx = (int)Math.round(1000*Math.cos(_theta + Math.PI/2)),%0A            ny = (int)Math.round(1000*Math.sin(_theta + Math.PI/2));%0A        g.setColor(Color.pink);%0A        g.drawLine(_center.x, _center.y, nx, ny);%0A%0A        // figure out which side the line is on%0A        String str;%0A        int side = GeomUtil.whichSide(_center, _theta, _spot);%0A        if (side %3E 0) %7B%0A            str = %22R%22;%0A        %7D else if (side %3C 0) %7B%0A            str = %22L%22;%0A        %7D else %7B%0A            str = %22O%22;%0A        %7D%0A%0A        g.setColor(Color.black);%0A        g.drawString(str, _spot.x, _spot.y);%0A%0A        // kick theta along for the next tick because it's fun%0A//         _theta += (float)(Math.PI/100);%0A    %7D%0A%0A    public void mouseDragged (MouseEvent event)%0A    %7B%0A    %7D%0A%0A    public void mouseMoved (MouseEvent event)%0A    %7B%0A        _spot.x = event.getX();%0A        _spot.y = event.getY();%0A        repaint();%0A    %7D%0A%0A    public static void main (String%5B%5D args)%0A    %7B%0A        JFrame frame = new JFrame();%0A        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);%0A        frame.getContentPane().add(new WhichSideViz(), BorderLayout.CENTER);%0A        frame.setSize(300, 300);%0A        SwingUtil.centerWindow(frame);%0A        frame.show();%0A    %7D%0A%0A    protected float _theta = (float)(3 * Math.PI / 5);%0A    protected Point _center;%0A    protected Point _spot = new Point();%0A%7D%0A

Test app for GeomUtil.whichSide().