This is a whole assignment with rectangles and complicated polygon. This is also our one and only clipping assignment well.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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,
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.
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?
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.
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?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
If you don't understand my answer, don't ignore it, ask a question.
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.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.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?
If you don't understand my answer, don't ignore it, ask a question.
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?
If you don't understand my answer, don't ignore it, ask a question.
Using the compare method? I guess?
What class is the compare() method in?
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.
http://i.imgur.com/f4ANQ.png
I think I will implement this design.
Good luck.
If you don't understand my answer, don't ignore it, ask a question.
Do i need anything else besides this method?