Solved

How to merge two polygons into one

Posted on 2004-08-05
14
1,596 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now