Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to merge two polygons into one

Posted on 2004-08-05
14
1,637 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
map related example 6 55
table example 4 32
java example issue 3 19
Java program running SQL query 5 37
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

791 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