Solved

polygon offset algorithm

Posted on 1997-11-05
13
2,577 Views
Last Modified: 2006-11-17
looking for an algorithm to draw an offset from a polygon

i have an array of vertices and the angle of each angle

Thank's
0
Comment
Question by:ct_consultant
  • 4
  • 4
  • 2
  • +2
13 Comments
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1256167
What do you mean by an 'offset from a polygon' ?
I also would like to know more about your polygon. Is it in 2d or 3d, can it be concave or is it always convex?
.luc.
0
 

Author Comment

by:ct_consultant
ID: 1256168
I have an array of coordinates x,y (2d) that can be in any direction
and the polygon does not have to be closed

I have the offset in milimiters and can calculate the angle of each vertice

What i need to do is recreate the same ''shape'' but taking into
considaration the offset set by the user. dont worry about conversion of any kind i take care of that already
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 total points
ID: 1256169
Since you have the angles and the angles are not affected by offsets, why don't you add the offset into every single vertex before drawing the polygon. For example, if you had a square at (0, 0) - (10, 10) and the offset is (5, 5), the angles between the vertices don't change but the vertices do: You'll get (0+5, 0+5) - (10+5, 10+5) which is what you want: (5, 5) - (15, 15).
0
 

Author Comment

by:ct_consultant
ID: 1256170
it is not a copy of the shape, cause if you draw a square, an try
to draw on offset of that square from the inside or outside. the length of each vertices will be shorter or longer tan the original shape. this it what i need to calculate.




0
 
LVL 84

Expert Comment

by:ozo
ID: 1256171
So how do you specify an "offset"?  Do you just want to multiply all the coordinates by a constant?
0
 

Author Comment

by:ct_consultant
ID: 1256172
the offset is a double specified by the user

it can be between -1000 and 1000 in mm, but don't worry about
conversion.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1256173
How can an offset change the length of the vertices. What do you mean by an 'offset'. It certainly isn't a linear transformation (like a translation (thui's answer), or a rotation) because they don't change the vertices. So what is an 'offset'?
.luc.
0
 
LVL 84

Expert Comment

by:ozo
ID: 1256174
I also don't understand what you mean by an offset "from the inside or outside"
Is -10mm inside or outside a square?
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1256175
Do you mean scaling?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1256176
Maybe the idea is to add a border around the polygon?
(in which case, you could just thicken each edge,
but how would you want to handle corner rounding?)
0
 
LVL 1

Expert Comment

by:meessen
ID: 1256177
It looks like what you call offset polygone is a new polygone whose lines are at a given distance of the original polygone.
It is not like shrinking or growing the polygone. Except for special shapes like a cube for instance. For a rectangle for instance, after growin, the border distance with the original rectangle will not be constant.

I have heard of a similar application for processing fonts outline. The problem is trivial for convex shapes and complex for concave shapes because in this case the new polygone may have self overlapping parts.

If my understanding is right, you have to find the equation of the prallel line at the given offset(distance) and then compute the instersection of two consecutive segments to compute the new polygone corner points.

For concave polygones, if you want a non overlapping offset polygon, you wil need to clip and this may result in more than one polygone.

Don't you think 200 points is too much for such questions ?
0
 

Author Comment

by:ct_consultant
ID: 1256178
in the case of overlapping i can always find the intersection of the two point, but if you do a mirror of tha line you will find that there is a missing segment this is what i need to resolve my
problem... thank's

maybe 200 hundred is a little too much, but i need a quick answer
0
 
LVL 84

Expert Comment

by:ozo
ID: 1256179
So it sounds like you are thickening each edge, and your problem is how to handle the corners?
If so, 4 basic methods are:
1) Extend the lines until they intersect (which can extend long tails at sharp corners)
2) Round the corners with a circular arc.
3) Connect the ends of the "offset" lines with a straight segment
4) Just leave the corner open.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

747 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

16 Experts available now in Live!

Get 1:1 Help Now