Solved

How to merge two polygons into one

Posted on 2004-08-05
14
1,625 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 16

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 16

Expert Comment

by:krakatoa
ID: 11734196
>> ahlve = halve.
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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 16

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 125 total points
ID: 11986376
Use the Line class, and it's intersectsLine() method to determine if two lines intersect.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

823 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