Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Polygons

Status
Not open for further replies.

SteveD73

Programmer
Jan 5, 2001
109
GB
Hello

I have a 4 sided polygon which is defined by the points p1, p2, p3, and p4. This polygon is reffered to as the maydetect zone. The problem is I need to draw another polygon which is exactly the same shape but smaller. The smaller polygon must go inside the big polygon.

The question is:

How can I calculate the points in the small polygon?

Thanks for any help.
 
what I would first say is look at a square because it is a special case. Say you know you want to move the x coordinate in by 5 and the y back by 5, this is easy to visualize in your head as a square inside a square. Granted a 4 sided poly will always be handled in this manner. It is when you get into 5,6,7... sided polys that things get a little more crazy. How i would go about it then is put one axis of the object on the x axis and look at it from that perspective. I would suggest a rotation algorithm and rotate each point to (0,0). From there you could calculate the repositioning. As for the algorithm itself, i dont know off the top of my head how to go about it. Another approach could be to use Linear Algebra.

Matt
 
It seems to me (after a bit of doodling) that the vertices for the inner polygon (4-sided only, mind you, or perhaps even, I'm not sure) will always lie on the 'diagonals' of the polygon. You could check the length of the diagonals, then move in along those lines an appropriate distance.
 
Select a point on one of the two diagonals of the original polygon as one vertex. then make a line which pararells to one side of the polygon. This line will intersect with another diagonal. The intersection point must be another vertex. Keep doing this, you can get all the 4 vertices of the inner polygon. The idea here is not very difficult for you to change it into codes.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top