Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PolyLine or Polygon?

 
Ravi Kotha
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ravi Kotha
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Marshal
Pie
Posts: 21412
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic