Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)

Paste

Pasted as Java by twak ( 16 years ago )
package notrobust;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.vecmath.Point2d;
import utils.FrameDumper;

/**
 *
 * @author twak
 */
public class Orientation extends JPanel
{

    public int calculate (Point2d p, Point2d q, Point2d r, double ep )
    {
        double res = (q.x - p.x) * (r.y - p.y ) - (q.y - p.y) * (r.x - p.x );
        return res > ep ? 1 : res < -ep ? -1 : 0;
    }

    public int calculate (int x, int y, double ep)
    {
        Point2d p = new Point2d( 0.5, 0.5 );
        Point2d q = new Point2d( 12, 12 );
        Point2d r = new Point2d( 24, 24 );

//        p.x +=  Math.pow( 2, -53) * x;
//        p.y +=  Math.pow( 2, -53) * y;

        for (int x2 = 0; x2 < x; x2++)
        {
            p.x += Math.ulp( p.x );
        }

        for (int y2 = 0; y2 < y; y2++)
        {
            p.y += Math.ulp( p.y );
        }

        return calculate (p,q,r, ep);
    }

    @Override
    public void paint( Graphics g )
    {
        paint( g, getWidth(), getHeight(), 0);
    }
    public void paint( Graphics g, int w, int h, double ep )
    {
        for (int x = 0; x < w; x++ )
            for ( int y = 0; y < h; y++ )
            {
                int res = calculate( x, y, ep );
                g.setColor( res == -1 ? Color.blue : res == 0 ? Color.yellow : Color.red );
                g.fillRect( x, y, 1, 1 );
            }
    }

    public void go()
    {
        double ep = 0;
        
        for ( int i = 0; i < 150; i++ )
        {
            Graphics g = FrameDumper.dumpFrame( 1024, 1024 );
            paint( g, 1024, 1024, ep );
            ep += Math.pow( 2, -44);
            System.out.println("working on "+i+" with epsilon "+ep);
        }
    }

    public static void main (String[] args)
    {
        new Orientation().go();

//        JFrame frame= new JFrame("robust...?");
//        JPanel p = new JPanel();
//        p.setLayout( new GridLayout () );
//
//        p.add( new Orientation() );
//
//        frame.setContentPane( p );
//
//        frame.setSize(300,300);
//
//        frame.setVisible( true );
    }
}

 

Revise this Paste

Your Name: Code Language: