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 1 of 3 123 LastLast
Results 1 to 25 of 51

Thread: Polygon Clipping Java, Help Please.

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

    Default Polygon Clipping Java, Help Please.

    Hello, I am stuck on this Polygon Clipping Assignment.
    This is what the result should look like.
    clipTest.jpg

    Here's the package I am working with. It's java so under the java folders. I am only allowed to edit the Clipper.java file.
    cg1-clip.zip

    This is what I have so far:

    //
    //  Clipper.java
    //  
    //
    //  Created by Joe Geigel on 1/21/10.
    //  Copyright 2010 __MyCompanyName__. All rights reserved.
    //
     
    /**
     * Object for performing clipping
     *
     */
     
    public class clipper {
     
        /**
         * clipPolygon
         * 
         * Clip the polygon with vertex count in and vertices inx/iny
         * against the rectangular clipping region specified by lower-left corner
         * (x0,y0) and upper-right corner (x1,y1). The resulting vertices are
         * placed in outx/outy.  
         * 
         * The routine should return the with the vertex count of polygon
         * resultinhg from the clipping.
         *
         * @param in the number of vertices in the polygon to be clipped
         * @param inx - x coords of vertices of polygon to be clipped.
         * @param int - y coords of vertices of polygon to be clipped.
         * @param outx - x coords of vertices of polygon resulting after clipping.
         * @param outy - y coords of vertices of polygon resulting after clipping.
         * @param x0 - x coord of lower left of clipping rectangle.
         * @param y0 - y coord of lower left of clipping rectangle.
         * @param x1 - x coord of upper right of clipping rectangle.
         * @param y1 - y coord of upper right of clipping rectangle.
         *
         * @return number of vertices in the polygon resulting after clipping
         * 
         */
    	public float intersectX;
    	public float intersectY;
    	public float clipXmin;
    	public float clipYmin;
    	public float clipYmax;
    	public float clipXmax;
    	public int clipBorder;
     
        public int clipPolygon(int in, float inx[], float iny[], float outx[],
                    float outy[],  float x0, float y0, float x1, float y1)
        {
            int numberOfVerticies = 0;
            int n;
     
            float Lx,Ly,Cx,Cy;
     
            Lx = inx[in-1];
            Ly = iny[in-1];
     
            for (n = 0; n < in; n++){
    			Cx = inx[n];
    			Cy = iny[n];
     
     
     
    		if(isInside(Cx, Cy, clipBorder)){
    			if(isInside(Lx,Ly,clipBorder)){
    				outx[numberOfVerticies] = Cx;
    				outy[numberOfVerticies] = Cy;
    				numberOfVerticies++;
     
     
    			}
    			else{
    				isIntersect(Lx,Ly,Cx,Cy,clipBorder);
    				outx[numberOfVerticies] = intersectX;
    				outy[numberOfVerticies] = intersectY;
    				numberOfVerticies++;
    				outx[numberOfVerticies] = Cx;
    				outy[numberOfVerticies] = Cy;
    				numberOfVerticies++;
     
     
    			}
    		}
    		else{
    				if(isInside(Lx,Ly,clipBorder)){
    					isIntersect(Lx,Ly,Cx,Cy,clipBorder);
    					outx[numberOfVerticies] = intersectX;
    					outy[numberOfVerticies] = intersectY;
    					numberOfVerticies++;
     
    					}
    				}
    			Lx = Cx;
    			Ly = Cy;
     
     
    			}
            return numberOfVerticies; // should return number of verricies in clipped poly.
        }
     
     
     
    public boolean isInside(float newX, float newY, int clipBorder){
    	if(clipBorder == 0 && newY > clipYmin){
    		return true;
    	}
    	else if(clipBorder == 1 && newX > clipXmin){
    		return true;
    	}
    	else if(clipBorder == 2 && newY < clipYmax){
    		return true;
    	}
    	else if (clipBorder == 3 && newX < clipXmax){
    		return true;
    	}
    	return false;
    }
    public void isIntersect(float x0, float x1, float y0, float y1, int clipBorder){
    	float xDifference = x1 -x0;
    	float yDifference = y1 - y0;
     
    	if(xDifference == 0 || yDifference == 0){
     
    		if(clipBorder == 0){
    			intersectX = x0;
    			intersectY = clipYmin;
    		}
    		else if(clipBorder == 1){
    			intersectX = clipXmin;
    			intersectY = y0;
    		}
    		else if(clipBorder == 2){
    			intersectX = x0;
    			intersectY = clipYmax;
    		}
    		else if(clipBorder == 3){
    			intersectX = clipXmax;
    			intersectY = y0;
    		}
    		return;
    	}
    	if(clipBorder == 0){
     
    		//intersectX = x0 + ((((((int)xDifference) * ((int)clipYmin - (int)y0))<<8) / ((int)yDifference))>>8);
    		intersectX = x0 + ((clipYmax - y0)/(y1-y0/x1-x0));
    		intersectY = clipYmin;
    	}
    	else if(clipBorder == 1){
    		intersectX = clipXmin;
    		intersectY = (y1-y0/x1-x0)*(clipXmax-x0) + y0;
    		//intersectY = y0 + ((((((int)yDifference) * ((int)clipXmin - (int)x0))<<8) / ((int)xDifference))>>8);  
    	}
    	else if(clipBorder == 2){
    		//intersectX = x0 + ((((((int)xDifference) * ((int)clipYmax - (int)y0))<<8) / ((int)yDifference))>>8);
    		intersectX = x0+((clipYmin-y0)/(y1-y0/x1-x0));
    		intersectY = clipYmax;
    	}
    	else if(clipBorder == 3){
    		intersectX = clipXmax;
    		//intersectY = y0 + ((((((int)yDifference) * ((int)clipXmax - (int)x0))<<8) / ((int)xDifference))>>8);  
    		intersectY = (y1-y0/x1-x0)*(clipXmax-x0) + y0;
    	}
    }
     
    }


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Polygon Clipping Java, Help Please.

    What is your question?

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

    Default Re: Polygon Clipping Java, Help Please.

    What am I doing wrong?

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

    Default Re: Polygon Clipping Java, Help Please.

    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.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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:
    if(false) {   //  skip following code
     .....
       code to be skipped
    ....
    } //  end if(false)
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    Quote Originally Posted by Norm View Post
    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:
    if(false) {   //  skip following code
     .....
       code to be skipped
    ....
    } //  end if(false)
    sweet, i'll try it.

    --- Update ---

    Alright, the condition is always true, it seems. Do you have any ideas how to fix this algorithm then?

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    Sorry, I have no idea what the code that is executed is supposed to do. I can't see any comments in the code describing what the various methods are supposed to do.

    the condition is always true
    You'll have to continue adding println() statements to see what the code is doing. If you know what it's supposed to do, the print outs will show you where it is going wrong.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    It's suppose to clip the polygons so it's half shaded. The image is the results.
    I did do the println() and it didn't help me to figure out why it's always true.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    why it's always true.
    What values do the variables need to have for the method to return false?
    How can the variables ever get those values?

    Add more printlns to show the values of the variables being used to determine true or false results.

    Post the code with the println statements you are using so we can see if they are useful to show you what the code is doing.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    Quote Originally Posted by Norm View Post
    What values do the variables need to have for the method to return false?
    How can the variables ever get those values?

    Add more printlns to show the values of the variables being used to determine true or false results.

    Post the code with the println statements you are using so we can see if they are useful to show you what the code is doing.
    //
    //  Clipper.java
    //  
    //
    //  Created by Joe Geigel on 1/21/10.
    //  Copyright 2010 __MyCompanyName__. All rights reserved.
    //
     
    /**
     * Object for performing clipping
     *
     */
     
    public class clipper {
     
        /**
         * clipPolygon
         * 
         * Clip the polygon with vertex count in and vertices inx/iny
         * against the rectangular clipping region specified by lower-left corner
         * (x0,y0) and upper-right corner (x1,y1). The resulting vertices are
         * placed in outx/outy.  
         * 
         * The routine should return the with the vertex count of polygon
         * resultinhg from the clipping.
         *
         * @param in the number of vertices in the polygon to be clipped
         * @param inx - x coords of vertices of polygon to be clipped.
         * @param int - y coords of vertices of polygon to be clipped.
         * @param outx - x coords of vertices of polygon resulting after clipping.
         * @param outy - y coords of vertices of polygon resulting after clipping.
         * @param x0 - x coord of lower left of clipping rectangle.
         * @param y0 - y coord of lower left of clipping rectangle.
         * @param x1 - x coord of upper right of clipping rectangle.
         * @param y1 - y coord of upper right of clipping rectangle.
         *
         * @return number of vertices in the polygon resulting after clipping
         * 
         */
    	private float intersectX;
    	private float intersectY;
    	private float clipXmin;
    	private float clipYmin;
    	private float clipYmax;
    	private float clipXmax;
    	private int clipBorder;
     
        public int clipPolygon(int in, float inx[], float iny[], float outx[],
                    float outy[],  float x0, float y0, float x1, float y1)
        {
            int numberOfVerticies = 0;
            int n;
     
            float Lx,Ly,Cx,Cy;
     
            Lx = inx[in-1];
            Ly = iny[in-1];
     
            for (n = 0; n < in; n++){
    			Cx = inx[n];
    			Cy = iny[n];
     
     
     
    		if(isInside(Cx, Cy, clipBorder)){
    			System.out.println("true if the verticies are inside");
    			if(isInside(Lx,Ly,clipBorder)){
    				outx[numberOfVerticies] = Cx;
    				outy[numberOfVerticies] = Cy;
    				numberOfVerticies++;
    				System.out.println("set verticies");
     
    			}
    			else{
     
    				isIntersect(Lx,Ly,Cx,Cy,clipBorder);
    				outx[numberOfVerticies] = intersectX;
    				outy[numberOfVerticies] = intersectY;
    				numberOfVerticies++;
    				outx[numberOfVerticies] = Cx;
    				outy[numberOfVerticies] = Cy;
    				numberOfVerticies++;
    				System.out.println("If the clipping window intersects the vertices");
     
    			}
    		}
    		else{
    				if(isInside(Lx,Ly,clipBorder)){
    					isIntersect(Lx,Ly,Cx,Cy,clipBorder);
    					outx[numberOfVerticies] = intersectX;
    					outy[numberOfVerticies] = intersectY;
    					numberOfVerticies++;
    					System.out.println("Set new verticies if intersected");
    					}
    				}
    			Lx = Cx;
    			Ly = Cy;
     
     
    			}
            return numberOfVerticies; // should return number of verricies in clipped poly.
        }
     
     
     
    public boolean isInside(float newX, float newY, int clipBorder){
    	if(clipBorder == 0 && newY > clipYmin){
    		return true;
    	}
    	else if(clipBorder == 1 && newX > clipXmin){
    		return true;
    	}
    	else if(clipBorder == 2 && newY < clipYmax){
    		return true;
    	}
    	else if (clipBorder == 3 && newX < clipXmax){
    		return true;
    	}
    	return false;
    }
    public void isIntersect(float x0, float x1, float y0, float y1, int clipBorder){
    	float xDifference = x1 -x0;
    	float yDifference = y1 - y0;
     
    	if(xDifference == 0 || yDifference == 0){
     
    		if(clipBorder == 0){
    			intersectX = x0;
    			intersectY = y0;
    		}
    		else if(clipBorder == 1){
    			intersectX = x1;
    			intersectY = y0;
    		}
    		else if(clipBorder == 2){
    			intersectX = x0;
    			intersectY = y1;
    		}
    		else if(clipBorder == 3){
    			intersectX = x1;
    			intersectY = y0;
    		}
    		return;
    	}
    	if(clipBorder == 0){
     
    		//intersectX = x0 + ((((((int)xDifference) * ((int)clipYmin - (int)y0))<<8) / ((int)yDifference))>>8);
    		intersectX = x0 + ((clipYmax - y0)/(y1-y0/x1-x0));
    		intersectY = y1;
    	}
    	else if(clipBorder == 1){
    		intersectX = x0;
    		intersectY = (y1-y0/x1-x0)*(clipXmin-x0) + y0;
    		//intersectY = y0 + ((((((int)yDifference) * ((int)clipXmin - (int)x0))<<8) / ((int)xDifference))>>8);  
    	}
    	else if(clipBorder == 2){
    		//intersectX = x0 + ((((((int)xDifference) * ((int)clipYmax - (int)y0))<<8) / ((int)yDifference))>>8);
    		intersectX = x0+((clipYmin-y0)/(y1-y0/x1-x0));
    		intersectY = y0;
    	}
    	else if(clipBorder == 3){
    		intersectX = x1;
    		//intersectY = y0 + ((((((int)yDifference) * ((int)clipXmax - (int)x0))<<8) / ((int)xDifference))>>8);  
    		intersectY = (y1-y0/x1-x0)*(clipXmax-x0) + y0;
    	}
    }
     
    }

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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:
    	if(clipBorder == 0 && newY > clipYmin){
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    Quote Originally Posted by Norm View Post
    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:
    	if(clipBorder == 0 && newY > clipYmin){
    //
    //  Clipper.java
    //  
     
    //
     
    /**
     * Object for performing clipping
     *
     */
     
    public class clipper {
     
        /**
         * clipPolygon
         * 
         * Clip the polygon with vertex count in and vertices inx/iny
         * against the rectangular clipping region specified by lower-left corner
         * (x0,y0) and upper-right corner (x1,y1). The resulting vertices are
         * placed in outx/outy.  
         * 
         * The routine should return the with the vertex count of polygon
         * resultinhg from the clipping.
         *
         * @param in the number of vertices in the polygon to be clipped
         * @param inx - x coords of vertices of polygon to be clipped.
         * @param int - y coords of vertices of polygon to be clipped.
         * @param outx - x coords of vertices of polygon resulting after clipping.
         * @param outy - y coords of vertices of polygon resulting after clipping.
         * @param x0 - x coord of lower left of clipping rectangle.
         * @param y0 - y coord of lower left of clipping rectangle.
         * @param x1 - x coord of upper right of clipping rectangle.
         * @param y1 - y coord of upper right of clipping rectangle.
         *
         * @return number of vertices in the polygon resulting after clipping
         * 
         */
    	private float intersectX;
    	private float intersectY;
    	private float clipXmin;
    	private float clipYmin;
    	private float clipYmax;
    	private float clipXmax;
    	private int clipBorder;
     
        public int clipPolygon(int in, float inx[], float iny[], float outx[],
                    float outy[],  float x0, float y0, float x1, float y1)
        {
            int numberOfVerticies = 0;
            int n;
     
            float Lx,Ly,Cx,Cy;
     
            Lx = inx[in-1];
            Ly = iny[in-1];
     
            for (n = 0; n < in; n++){
    			Cx = inx[n];
    			Cy = iny[n];
     
    		System.out.println(intersectX);	
    		System.out.println(intersectY);
    		System.out.println(Lx);
    		System.out.println(Ly);
    		System.out.println(Cx);
    		System.out.println(Cy);
    		System.out.println(numberOfVerticies);
     
     
     
    		if(isInside(Cx, Cy)){
     
    			if(isInside(Lx,Ly)){
    				outx[numberOfVerticies] = Cx;
    				outy[numberOfVerticies] = Cy;
    				numberOfVerticies++;
     
     
    			}
    			else{
     
    				isIntersect(x0, x1, y0, y1);
    				outx[numberOfVerticies] = intersectX;
    				outy[numberOfVerticies] = intersectY;
    				numberOfVerticies++;
    				outx[numberOfVerticies] = Cx;
    				outy[numberOfVerticies] = Cy;
    				numberOfVerticies++;
    				System.out.println("If the clipping window intersects the vertices");
     
    			}
    		}
    		else{
    				if(isInside(Lx,Ly)){
    					isIntersect(x0, x1, y0, y1);
    					outx[numberOfVerticies] = intersectX;
    					outy[numberOfVerticies] = intersectY;
    					numberOfVerticies++;
    					System.out.println("Set new verticies if intersected");
    					}
    				}
    			Lx = Cx;
    			Ly = Cy;
     
     
    			}
            return numberOfVerticies; // should return number of verricies in clipped poly.
        }
     
     
     
    public boolean isInside(float newX, float newY){
    	System.out.println(newY);
    	System.out.println(newX);
    	System.out.println(clipBorder);
    	System.out.println(clipYmin);
    	System.out.println(clipYmax);
    	System.out.println(clipXmax);
    	System.out.println(clipXmin);
     
    	if(clipBorder == 0 && newY > clipYmin){
    		return true;
    	}
    	else if(clipBorder == 1 && newX > clipXmin){
    		return true;
    	}
    	else if(clipBorder == 2 && newY < clipYmax){
    		return true;
    	}
    	else if (clipBorder == 3 && newX < clipXmax){
    		return true;
    	}
    	return false;
    }
    public void isIntersect(float x0, float x1, float y0, float y1){
    	float xDifference = x1 -x0;
    	float yDifference = y1 - y0;
     
    	if(xDifference == 0 || yDifference == 0){
     
    		if(clipBorder == 0){
    			intersectX = x0;
    			intersectY = y0;
    		}
    		else if(clipBorder == 1){
    			intersectX = x1;
    			intersectY = y0;
    		}
    		else if(clipBorder == 2){
    			intersectX = x0;
    			intersectY = y1;
    		}
    		else if(clipBorder == 3){
    			intersectX = x1;
    			intersectY = y0;
    		}
    		return;
    	}
    	if(clipBorder == 0){
     
    		//intersectX = x0 + ((((((int)xDifference) * ((int)clipYmin - (int)y0))<<8) / ((int)yDifference))>>8);
    		intersectX = x0 + ((clipYmax - y0)/(y1-y0/x1-x0));
    		intersectY = y1;
    	}
    	else if(clipBorder == 1){
    		intersectX = x0;
    		intersectY = (y1-y0/x1-x0)*(clipXmin-x0) + y0;
    		//intersectY = y0 + ((((((int)yDifference) * ((int)clipXmin - (int)x0))<<8) / ((int)xDifference))>>8);  
    	}
    	else if(clipBorder == 2){
    		//intersectX = x0 + ((((((int)xDifference) * ((int)clipYmax - (int)y0))<<8) / ((int)yDifference))>>8);
    		intersectX = x0+((clipYmin-y0)/(y1-y0/x1-x0));
    		intersectY = y0;
    	}
    	else if(clipBorder == 3){
    		intersectX = x1;
    		//intersectY = y0 + ((((((int)yDifference) * ((int)clipXmax - (int)x0))<<8) / ((int)xDifference))>>8);  
    		intersectY = (y1-y0/x1-x0)*(clipXmax-x0) + y0;
    	}
    }
     
    }

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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:
          System.out.println("sb="+sb +", y="+y+", ln="+ln);
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    Quote Originally Posted by Norm View Post
    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.

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    Quote Originally Posted by Norm View Post
    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.

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    clipBorder isn't working for me.
    Please explain what "isn't working" means.

    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()
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    Quote Originally Posted by Norm View Post
    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().

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

    Quote Originally Posted by Norm View Post
    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.

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Polygon Clipping Java, Help Please.

    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.
    If you don't understand my answer, don't ignore it, ask a question.

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

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

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Polygon Clipping Java, Help Please.

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

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 3 123 LastLast

Similar Threads

  1. Clipping while scrolling
    By copeg in forum AWT / Java Swing
    Replies: 0
    Last Post: May 24th, 2010, 09: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, 03:28 PM