Interesting problem. I quickly write a Swing program to represent those dots and lines.
And you can count your self pretty happy then. Haha.
package com.seabook.google.algorithm;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class FaceFinder extends JPanel {
private static List<Line> lines = new ArrayList<Line>();
private static String[] lines1 = new String[] { "0 0 100 100",
"0 100 100 0" };
private static String[] lines2 = new String[] { "10 10 20 10",
"10 10 10 20", "20 20 10 20", "20 20 20 10" };
private static String[] lines3 = new String[] { "0 0 0 10", "1 0 1 10",
"2 0 2 10", "3 0 3 10", "4 0 4 10", "5 0 5 10", "6 0 6 10",
"7 0 7 10", "8 0 8 10", "9 0 9 10", "10 0 10 10", "0 0 10 0",
"0 1 10 1", "0 2 10 2", "0 3 10 3", "0 4 10 4", "0 5 10 5",
"0 6 10 6", "0 7 10 7", "0 8 10 8", "0 9 10 9", "0 10 10 10" };
private static String[] line4 = new String[] { "0 0 0 1", "0 0 0 2",
"0 0 0 3", "0 0 0 4", "0 0 0 5", "0 0 1 0", "0 0 2 0", "0 0 3 0",
"0 0 4 0", "0 0 5 0", "5 0 0 5", "4 0 0 4", "3 0 0 3", "2 0 0 2",
"1 0 0 1" };
private static String[] line5 = new String[] { "0 0 0 1", "0 0 1 0",
"0 0 1 1", "1 0 1 1", "0 1 1 1", "1 0 0 1" };
public static void main(String[] args) {
parseLines(line5);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
private static void parseLines(String[] pLines) {
for (String line : pLines) {
List<Integer> linePoints = new ArrayList<Integer>();
String[] point = line.split(" ");
for (String p : point) {
linePoints.add(Integer.valueOf(p) * 10);
}
Line tmpLine = new Line(linePoints.toArray(new Integer[4]));
lines.add(tmpLine);
}
}
private static void createAndShowGUI() {
JFrame frame = new JFrame("FaceFinder");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the content pane.
FaceFinder newContentPane = new FaceFinder();
newContentPane.setOpaque(true); // content panes must be opaque
frame.setContentPane(newContentPane);
// Display the window.
frame.pack();
frame.setVisible(true);
}
public FaceFinder() {
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (Line line : lines) {
int x1 = line.linePoints[0];
int y1 = line.linePoints[1];
int x2 = line.linePoints[2];
int y2 = line.linePoints[3];
g.drawLine(x1, y1, x2, y2);
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(1000, 1000);
}
}
class Line {
Integer[] linePoints = new Integer[4];
public Line(Integer[] linePoints) {
this.linePoints = linePoints;
}
}