I'm trying to clip out of some of the parts in each polygon. I'm stuck on that and I been debugging since this post but somehow my method isIntersect isn't being called/used. What I have now is all the polygon is filled but I need to make it look like the first image I posted.

January 9th, 2013, 03:25 PM

Norm

Re: Polygon Clipping Java, Help Please.

Quote:

my method isIntersect isn't being called/used.

The calls to that method are nested inside some if statements. Do some debugging to see why the conditions are not correct for the code with the method call to be executed.
One debug technique is to add lots of println() statements to print out the values of variables that are used to control logic flow in the code.

Suggestion: remove all but one of the calls to the clipping code to reduce the debugging output.
One way is to wrap the code to be skipped inside of an if statement that is never true:

The calls to that method are nested inside some if statements. Do some debugging to see why the conditions are not correct for the code with the method call to be executed.
One debug technique is to add lots of println() statements to print out the values of variables that are used to control logic flow in the code.

Suggestion: remove all but one of the calls to the clipping code to reduce the debugging output.
One way is to wrap the code to be skipped inside of an if statement that is never true:

Your printlns don't show the values of ANY of the variables used in the logic. You need to see the values of ALL the variables used in the logic so you see what the program is doing. For example, you need to print the values of all 3 of the variables used in this statement and others like it:

Code :

if(clipBorder == 0 && newY > clipYmin){

January 10th, 2013, 01:23 PM

wtosh

Re: Polygon Clipping Java, Help Please.

Quote:

Originally Posted by Norm

Your printlns don't show the values of ANY of the variables used in the logic. You need to see the values of ALL the variables used in the logic so you see what the program is doing. For example, you need to print the values of all 3 of the variables used in this statement and others like it:

What is being printed out? Does the output show you why the methods are always returning true?
What variable's values need to be changed for the method to return false?

Your println output is impossible to read. All it prints are numbers. How can you tell the values of any of the variables? Add id Strings to give names to the values.
Also there are too many lines being printed.
You can print more than one value on a line.
For example:

Code :

System.out.println("sb="+sb +", y="+y+", ln="+ln);

January 10th, 2013, 01:33 PM

wtosh

Re: Polygon Clipping Java, Help Please.

Quote:

Originally Posted by Norm

What is being printed out? Does the output show you why the methods are always returning true?
What variable's values need to be changed for the method to return false?

The printed vaubles does not tell me what's going on. The intersectx and y are always 0 since i never instaniated that. LyxCxy are always changing.

January 10th, 2013, 01:36 PM

Norm

Re: Polygon Clipping Java, Help Please.

Quote:

The printed vaubles does not tell me what's going on

The changes in the values of the variables IS WHAT IS GOING ON. If the values of the variables never change, then there is nothing happening.

January 10th, 2013, 01:47 PM

wtosh

Re: Polygon Clipping Java, Help Please.

Quote:

Originally Posted by Norm

The changes in the values of the variables IS WHAT IS GOING ON. If the values of the variables never change, then there is nothing happening.

How would I do the intersect method? If clipBorder isn't working for me.

January 10th, 2013, 01:53 PM

Norm

Re: Polygon Clipping Java, Help Please.

Quote:

clipBorder isn't working for me.

Please explain what "isn't working" means.

Quote:

How would I do the intersect method?

What do you mean by "do the intersect method"?
What is the name of the method you are talking about? I don't see a method named: intersect()

January 10th, 2013, 03:53 PM

wtosh

Re: Polygon Clipping Java, Help Please.

Quote:

Originally Posted by Norm

Please explain what "isn't working" means.

What do you mean by "do the intersect method"?
What is the name of the method you are talking about? I don't see a method named: intersect()

I believe there is 2 types of polygons. I am using to clip with and the other is the polygon i need to clip. How am i suppose to clip with that polygon, I believe it's the x0,x1,y0,y1.

As for the intersect, I mean the method isIntersect().

January 10th, 2013, 04:13 PM

Norm

Re: Polygon Clipping Java, Help Please.

Quote:

How am i suppose to clip with that polygon, I believe it's the x0,x1,y0,y1.

Are you saying that you don't know what clipping means or how one polygon clips another?

What happens with the first test where one polygon is inside the other?
What should the clipPolygon() method return and what values should it put into the two arrays: outx and outy?

Have you worked out why the isInside() method never returns false?
What is that method testing and what does it mean for it to return true or to return false?
It has 3 args. What are each of them used for?

January 10th, 2013, 06:25 PM

wtosh

Re: Polygon Clipping Java, Help Please.

Quote:

Originally Posted by Norm

Are you saying that you don't know what clipping means or how one polygon clips another?

What happens with the first test where one polygon is inside the other?
What should the clipPolygon() method return and what values should it put into the two arrays: outx and outy?

Have you worked out why the isInside() method never returns false?
What is that method testing and what does it mean for it to return true or to return false?
It has 3 args. What are each of them used for?

I don't know how one polygon clips another is what i'm saying. The clipPolygon() should return the new vertices.
isInside is always true because there is no clipBorder value to compare it too?
The new X and Y variables are a temp variables to hold the new vertices, while the clipBorder should be the clip window that is comparing it too.

January 10th, 2013, 07:49 PM

Norm

Re: Polygon Clipping Java, Help Please.

Quote:

I don't know how one polygon clips another is what i'm saying

If you don't know what clip means, then you can not write the program.
Do some research to find out what it means to clip. Until you know that, you are wasting your time trying to write a program that clips.

January 10th, 2013, 08:01 PM

wtosh

Re: Polygon Clipping Java, Help Please.

Well my professor taught us what clipping means but the thing is that I don't know how to implement it into code.

January 10th, 2013, 08:10 PM

Norm

Re: Polygon Clipping Java, Help Please.

If you can't explain what clipping is, you won't be able to write a program to do it. Perhaps if you take a piece of paper and a pencil and draw the shapes and shade the clip region, you could see what needs to be done.
I'd think clipping would be easiest for rectangles. For many sided polygons I'd think it'd be a lot harder.

January 10th, 2013, 08:53 PM

wtosh

Re: Polygon Clipping Java, Help Please.

That's what i'm trying to do. Clip many sided polygons

January 10th, 2013, 09:21 PM

Norm

Re: Polygon Clipping Java, Help Please.

What are the steps the code must do to "clip a many sided polygon"?

The clipPolygon() method has a number of args and returns a count. It also is supposed to modify two arrays that are passed as args. The driver code uses those two arrays to create and fill the polygon for a display of the results.

Take the easier task of only working with rectangles for a first version. Work out the logic with paper and pencil and then try writing the code.
After the logic works for rectangles, THEN look at more complicated shapes.

How much of the Clipper class have your written and how much was given to you by the professor?