Click here to Skip to main content
15,888,461 members
Home / Discussions / Java
   

Java

 
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 
SuggestionRe: exe file Pin
Richard Deeming19-Mar-14 2:02
mveRichard Deeming19-Mar-14 2:02 
Questionopening .exe file Pin
Member 1003910918-Mar-14 22:59
Member 1003910918-Mar-14 22:59 
AnswerRe: opening .exe file Pin
TorstenH.24-Mar-14 4:55
TorstenH.24-Mar-14 4:55 
GeneralRe: opening .exe file Pin
Member 1003910925-Mar-14 1:03
Member 1003910925-Mar-14 1:03 
GeneralRe: opening .exe file Pin
TorstenH.25-Mar-14 4:11
TorstenH.25-Mar-14 4:11 
Questionhow to implement multiple languages and multiple themes in spring mvc Pin
basker A18-Mar-14 20:34
basker A18-Mar-14 20:34 
QuestionNew to this Pin
Wdutch18-Mar-14 13:18
Wdutch18-Mar-14 13:18 
AnswerRe: New to this Pin
Richard MacCutchan18-Mar-14 22:35
mveRichard MacCutchan18-Mar-14 22:35 
QuestionSQL Injection - Is this style of coding correct ? Pin
Jewel Joy117-Mar-14 19:32
Jewel Joy117-Mar-14 19:32 
AnswerRe: SQL Injection - Is this style of coding correct ? Pin
Tom Marvolo Riddle17-Mar-14 20:01
professionalTom Marvolo Riddle17-Mar-14 20:01 

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.