File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes PolyLine or Polygon? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "PolyLine or Polygon?" Watch "PolyLine or Polygon?" New topic

PolyLine or Polygon?

Ravi Kotha
Ranch Hand

Joined: Mar 02, 2006
Posts: 53
Hi thr,

In my application I have a list of points(x,y) coming from the GUI. Given the list of points I should be able to decide whether it is a polyline or polygon(It could be rectangle also, thts why I said polygon).

For Example:

I have list of points say p1(10,20), p2(50,60), p3(30,70), p4(50,30), p5(15,25).

Based on these points how can I determine the shape? Any ideas... Thanks in advance.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
I'm not sure I understand the question. Given the list of points [p1, p2, ... pn] what do you need to do? Are the points connected as listed p1 -> ... -> pn or do you trying to decide how the points should be connected to form a polygon?
[ December 28, 2006: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Ravi Kotha
Ranch Hand

Joined: Mar 02, 2006
Posts: 53
Points are already connected in the given order. But I want to know whether the shape formed is a "Polyline" or "Polygon"(it could be rectangle also).Did you get me?
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
A polygon is just a polyline with the first and last point being identical, correct? So you can simply check if that is the case.
Henry Wong

Joined: Sep 28, 2004
Posts: 20521

I think that it is a bit more complex than that. To be a valid polygon, I don't think that the line segments (sides of the polygon) are allowed to cross each other.

This means that you need to check each pair of sides (line segment). Lots of Algebra involved. Create algebraic equation that represent each line. Use simulaneous equations to solve for common point. etc. etc.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: PolyLine or Polygon?
It's not a secret anymore!