Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to merge two polygons into one

Posted on 2004-08-05
14
Medium Priority
?
1,793 Views
Last Modified: 2008-01-09
Hi,

Can someone tell me how to merge two polygons into one when they have overlap using Java?

In java.awt.Polygon :
     Polygon(int[] xPoints, int[] yPoints, int nPoints)
I saw it has addpoint method as:   void       addPoint(int x, int y)
but don't see merge method.

thanks in advance
0
Comment
Question by:ucool
  • 3
  • 3
  • 3
14 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11733243
there is no merge method that i'm aware of you'll need to implement it yourself.
0
 
LVL 17

Expert Comment

by:krakatoa
ID: 11734191
So how would you merge polygons of different types (if that's what you are saying), such as an acute triangle and a large square? Would you open up the angles of the triangle to meet the corners of the square? Or would you ahlve each object, scale them both up to the same relations, and then join them?
0
 
LVL 17

Expert Comment

by:krakatoa
ID: 11734196
>> ahlve = halve.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:ucool
ID: 11735828
To keep question simple, to merge two rectangle see below: (a) -> (b)

----------
|            |
|      -----|-----
|       |       |       |      
|___|___|___|
(a)

----------
|            |
|              |-----
|                        |      
|__________|
(b)

I think the key is how to find the cross points for two rectangles, then build a new polygon. The same as I need to find all cross points for two polygons, and merge to one.

thanks.
0
 
LVL 17

Expert Comment

by:krakatoa
ID: 11736041
I dont think I can be of much more help, since your diagrams are all to pot, but if the postion of the amalgamated polygon is not important, and the size neither is, then why not just draw a completely new one somewhere on the screen, rather than do all the calculations involved in this? If they are not the same proportions, I dont see how they can be joined together anyway, it doesnt make any sense.
0
 
LVL 92

Expert Comment

by:objects
ID: 11740560
you need to locate the polygon line segments that intersect, and create your new polygon based on those intercepts.
0
 
LVL 2

Author Comment

by:ucool
ID: 11926270
Hi Object,

>> you need to locate the polygon line segments that intersect, and create your new polygon based on those intercepts.

Can you give more explaination  based on coding perspective? It will be great if you can show as example. Since I still  can't get to how "to locate the polygon line segments that intersect"

thanks!
0
 
LVL 2

Author Comment

by:ucool
ID: 11979041
I don't think it is an accepted answer.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 11986376
Use the Line class, and it's intersectsLine() method to determine if two lines intersect.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question