Solved

How to merge two polygons into one

Posted on 2004-08-05
14
1,681 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
[X]
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
  • 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
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 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

728 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