Click here to Skip to main content
15,912,204 members
Home / Discussions / Java
   

Java

 
Questiongetting NullPointerException Pin
Member 1043154927-Mar-14 22:06
Member 1043154927-Mar-14 22:06 
SuggestionRe: getting NullPointerException Pin
Richard MacCutchan27-Mar-14 22:29
mveRichard MacCutchan27-Mar-14 22:29 
AnswerRe: getting NullPointerException Pin
TorstenH.31-Mar-14 1:17
TorstenH.31-Mar-14 1:17 
Questionproblem in hibernate mysql connecting Pin
chiku2427-Mar-14 19:57
chiku2427-Mar-14 19:57 
AnswerRe: problem in hibernate mysql connecting Pin
Member 1071490931-Mar-14 23:33
Member 1071490931-Mar-14 23:33 
AnswerRe: problem in hibernate mysql connecting Pin
Bhalchandra Sawant9-Apr-14 20:55
Bhalchandra Sawant9-Apr-14 20:55 
QuestionHow to connect into database and show the form from database Pin
Ah Nam Ge27-Mar-14 18:22
Ah Nam Ge27-Mar-14 18:22 
AnswerRe: How to connect into database and show the form from database Pin
Richard MacCutchan27-Mar-14 22:26
mveRichard MacCutchan27-Mar-14 22:26 
GeneralAbstract Classes in Java Pin
akcreative25-Mar-14 0:29
akcreative25-Mar-14 0:29 
GeneralRe: Abstract Classes in Java Pin
Richard MacCutchan25-Mar-14 1:30
mveRichard MacCutchan25-Mar-14 1:30 
GeneralRe: Abstract Classes in Java Pin
jschell25-Mar-14 13:29
jschell25-Mar-14 13:29 
GeneralRe: Abstract Classes in Java Pin
Bernhard Hiller25-Mar-14 21:39
Bernhard Hiller25-Mar-14 21:39 
GeneralRe: Abstract Classes in Java Pin
Member 1043154927-Mar-14 0:21
Member 1043154927-Mar-14 0:21 
GeneralRe: Abstract Classes in Java Pin
Member 1071490931-Mar-14 23:27
Member 1071490931-Mar-14 23:27 
Questionabout pointers Pin
Member 1030303423-Mar-14 17:39
Member 1030303423-Mar-14 17:39 
AnswerRe: about pointers Pin
Richard MacCutchan23-Mar-14 23:04
mveRichard MacCutchan23-Mar-14 23:04 
AnswerRe: about pointers Pin
Member 1043154927-Mar-14 0:25
Member 1043154927-Mar-14 0:25 
QuestionBrute force Convex Hull Pin
not_20-Mar-14 11:57
not_20-Mar-14 11:57 
I'm getting an incorrect output and getting some duplicates. i have traced through it several times both by myself and with my teacher but we can't find the mistake. Any help or guidance would be very much appreciated!!

This is my output:
BRUTE FORCE HULL
(45.49727, 99.40442)
(53.715485, 98.34267)
(45.49727, 99.40442)
(-90.16175, 96.802765)
(-97.703, 79.97963)
(-90.16175, 96.802765)
(91.41145, 88.82591)
(96.42737, 80.445724)
(91.41145, 88.82591)
(53.715485, 98.34267)
(96.42737, 80.445724)
(99.23712, 0.083602905)
(99.23712, 0.083602905)
(99.61636, -74.81982)
(82.97812, -94.3812)
(98.21695, -80.666794)

This is what the output should be"
BRUTE FORCE HULL
(45.49727, 99.40442)
(53.715485, 98.34267)
(91.41145, 88.82591)
(96.42737, 80.445724)
(99.23712, 0.083602905)
(99.61636, -74.81982)
(98.21695, -80.666794)
(82.97812, -94.3812)
(63.255356, -96.624664)
(-80.099915, -88.48059)
(-92.14374, -81.84515)
(-97.703, 79.97963)
(-90.16175, 96.802765)


Java
public class HullTest {
	
	ArrayList<Point> pointList = new ArrayList<Point>();
	@SuppressWarnings("unused")
	private int numPoints = -1;
	public void readFile(String points) throws FileNotFoundException
	{
		
		Scanner sc = new Scanner(new File(points));
		numPoints = sc.nextInt();
		while (sc.hasNextFloat()) 
	    {
			float x = sc.nextFloat();
			float y = sc.nextFloat();
			Point point = new Point(x,y);
			
			addPoint(point);
	    }
	    
	    sc.close();
	}
	
	public void addPoint(Point point)
	{
		pointList.add(point);
	}
	
	public ArrayList<Line> BruteForce()
	{
		ArrayList<Line> solutionPointsList = new ArrayList<Line>();
		
		for (int i = 0; i < pointList.size()-1; i++)
		{
			for (int j = i+1; j < pointList.size(); j ++)
			{
				boolean isSolutionLine = true;
				int initialSign = 0;
				Point pointA = pointList.get(i);
				Point pointB = pointList.get(j);
				float A = pointB.getY() - pointA.getY();
				float B = pointA.getX() - pointB.getX();
				float C = pointA.getX()*pointB.getY() - pointA.getY()*pointB.getX();
				for (int x = 0; x < pointList.size(); x++)
				{
					Point pointC = pointList.get(x);
					float pointRegion = A*pointC.getX() + B*pointC.getY() - C;
					if (initialSign != 0)
					{
						if (pointRegion > 0 && initialSign < 0)
						{
							isSolutionLine = false;
							break;
						} else if (pointRegion < 0 && initialSign > 0)
						{
							isSolutionLine = false;
							break;
						}
					} else
					{
						if (pointRegion > 0)
							initialSign = 1;
						else if (pointRegion < 0)
							initialSign = -1;
					}
				}
				
				if(isSolutionLine)
				{
					Line temp = new Line(pointA,pointB);
					solutionPointsList.add(temp);
				}
			}
		}
		
		return solutionPointsList;
		
	}
	
	public void PrintSolution ()
	{
		ArrayList<Line> list = BruteForce();
		System.out.println("BRUTE FORCE HULL");
		for (int i = 0; i < list.size(); i ++)
		{
			System.out.println( "(" + list.get(i).getPointA().getX() + ", " + list.get(i).getPointA().getY() + ")");
			System.out.println( "(" + list.get(i).getPointB().getX() + ", " + list.get(i).getPointB().getY() + ")");
		}
	}
	
	public static void main (String args[])
	{
		HullTest hull = new HullTest();
		try {
			hull.readFile(args[0]);
		} catch (FileNotFoundException e) {
			System.out.println("File not found!");
		}
		
		hull.PrintSolution();
	}
}


I also have the input file if needed.
AnswerRe: Brute force Convex Hull Pin
Kenneth Haugland20-Mar-14 12:57
mvaKenneth Haugland20-Mar-14 12:57 
QuestionByte aligned bitmap code compression Pin
Member 1068441319-Mar-14 19:04
Member 1068441319-Mar-14 19:04 
AnswerRe: Byte aligned bitmap code compression Pin
Richard MacCutchan19-Mar-14 23:26
mveRichard MacCutchan19-Mar-14 23:26 
Questionhelp Pin
Member1067140219-Mar-14 0:58
Member1067140219-Mar-14 0:58 
AnswerRe: help Pin
Richard MacCutchan19-Mar-14 3:53
mveRichard MacCutchan19-Mar-14 3:53 
Questionexe file Pin
Member 1003910918-Mar-14 23:57
Member 1003910918-Mar-14 23:57 
AnswerRe: exe file Pin
Bernhard Hiller19-Mar-14 0:46
Bernhard Hiller19-Mar-14 0:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.