This is a whole assignment with rectangles and complicated polygon. This is also our one and only clipping assignment well.
Printable View
This is a whole assignment with rectangles and complicated polygon. This is also our one and only clipping assignment well.
What design do you have for solving the problem?
The code looks like most of it was from your professor with a few incomplete changes made to it.
You need to make a design for the program before trying to write it,
The ClipTest, extendedCanvas, simpleCanvas were all classes provided by my instructor. I am NOT to modify them. The class I am able to change is the clipper.java class which came empty with the zip file.
For testing and debugging, there are changes that will be useful. For example limit the clip to only one of the cases vs all of them by commenting out all the ones that are not to be tested.
To make progress on this project, you first need to make a design.
I have a design, it's written in my notebook.
Are you using the design to write some new code? I'd suggest that you put the steps of the design into the code as comments as you write each part of the code.
I can't seem to convert the design into code.
What part(s) are you having problems with? Can you post the design steps you are trying to code?
The part where you have to intersect the polygon and create the new vertices.
So let's say the polygon edge that needs to be clipped hits the other polygon.
2. Intersection happens.
How can I code the intersection?
What are your design thoughts for finding the intersection? You need to work out the logic BEFORE writing the code.
Post #30: I have a design, it's written in my notebook.
Post #32: I can't seem to convert the design into code.
Post#33: Can you post the design steps you are trying to code?
I suggest for a first attempt that you work with rectangles. Save the weird shaped polygons for later.
My thoughts are that:
check left edge first. start at A, checks if clip line intersect edge A to B.
if it does make new vertice, save new verticie to A. Check next edge.
Repeat progress if intersect.
Move on if doesn't.
Do the same thing for the rest of the 3 clip lines.
The terms must be defined first.
What are A and B? How are they found/determined?
What object is the left edge on? The shape or the clipping rectangle.
How do you know if a clip line intersects an edge? This requires more logic to describe how it is done.
A and B are both given, I think. THe objects on the left are the left part of a edge that is of the polygon. I don't know how will the clip line intersects the edge......
Sorry, I can not understand your descriptions of the steps the program needs to take.
What is A and B? I did see their definition in your last post.
What is that? If the edge goes from left to right, is the left part of the edge the point at the start of the edge?Quote:
the left part of a edge
Try describing these three cases:
Detect no intersection.
Detect 100% overlap with clip rectangle larger than polygon
Detect 100% overlap with polygon larger than clip rectangle
A and B are both given, I think. THe objects on the left are the left part of a edge that is of the polygon. I don't know how will the clip line intersects the edge......
--- Update ---
"the left part of a edge"
I mean left part of an edge.
Detect no intersection: meaning there is an edge that does not intersect with another edge.
Detect 100% overlap with clip rectangle larger than polygon: Nothing happens.
Detect 100% overlap with polygon larger than clip rectangle: The clip rectangle clips where the polygon meets.
I assume an edge is a line connecting two points.Quote:
I mean left part of an edge.
What if the edge is a vertical line or a horizontal line?
What is the left part of a vertical line? Lines don't have much thickness to have a left or right part.
How much of an edge is in the left part of a horizontal edge? Is it one half of the edge/line?
What is the definition of "meets"? Definitions must be much much much more precise to be able to write code to implement them.Quote:
where the polygon meets.
How would you detect each of the three cases I mentioned? What are the steps the code must take to detect each of the three cases?
The clipPolygon() methods returns these things: the number of values in the two arrays and the values in the two arrays.
What should be returned for each of the three cases I asked about?
Yes, that is considered an edge.
If the edge is parallel to the clipping edge, it is unchanged.
---------- let's say this is a polygon edge. and +++++++++ this is the clipping edge.
Before before:
+++++++++
+---------+----------
+++++++++
After clipping:
+++++++++
+---------+
+++++++++
As soon as both edges touches, it is considered meet.
Uhhh, I think it should be detected by based on a boolean that is true or false if it meets?
It should return either a boolean or a float...I think
How would you detect each of the three cases I mentioned? What are the steps the code must take to detect each of the three cases?
The clipPolygon() methods returns these things: the number of values in the two arrays and the values in the two arrays.
What should be returned for each of the three cases I asked about?
Using the compare method? I guess?
What class is the compare() method in?
Uhhhh, I don't have one yet.
Ok, I guess I'll have to wait until you can get your design together.
I still recommend you design the program before coding any of it.
http://i.imgur.com/f4ANQ.png
I think I will implement this design.
Good luck.
Do i need anything else besides this method?