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.

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 51

Thread: Polygon Clipping Java, Help Please.

  1. #26
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    This is a whole assignment with rectangles and complicated polygon. This is also our one and only clipping assignment well.

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  3. #28
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  5. #30
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    I have a design, it's written in my notebook.

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  7. #32
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    I can't seem to convert the design into code.

  8. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  9. #34
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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?

  10. #35
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  11. #36
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  12. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  13. #38
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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......

  14. #39
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.
    the left part of a edge
    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?

    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.

  15. #40
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  16. #41
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    I mean left part of an edge.
    I assume an edge is a line connecting two points.
    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?

    where the polygon meets.
    What is the definition of "meets"? Definitions must be much much much more precise to be able to write code to implement them.

    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.

  17. #42
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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

  18. #43
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  19. #44
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    Using the compare method? I guess?

  20. #45
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    What class is the compare() method in?
    If you don't understand my answer, don't ignore it, ask a question.

  21. #46
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    Uhhhh, I don't have one yet.

  22. #47
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.

  23. #48
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    http://i.imgur.com/f4ANQ.png

    I think I will implement this design.

  24. #49
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,299
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Polygon Clipping Java, Help Please.

    Good luck.
    If you don't understand my answer, don't ignore it, ask a question.

  25. #50
    Junior Member
    Join Date
    Jan 2013
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Polygon Clipping Java, Help Please.

    Do i need anything else besides this method?

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. Clipping while scrolling
    By copeg in forum AWT / Java Swing
    Replies: 0
    Last Post: May 24th, 2010, 10:37 PM
  2. Creating Polygon (not visual)
    By teen-omar in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 11th, 2010, 04:28 PM