Hi, I am looking for a function in C that will hatch a polygon with lines of a given angle and distance apart, can anyone point me in the right direction? thanks...
This used to be one of the questions at the entry exam for the applicants at my previous working place. :-)
The basic algorithm would be the following:
1. Calculate the boundaries of the polygon according
Yes that's right,
the function would call a line(x1,y1,x2,y2) to hatch the polygon,
function call could look like this:
hatch(polystack ,item_count ,origin_point ,dirct_point ,spacing)...
does this help?
0
Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.
1. Learn how to raster-fill a polygon (this is a fundamental computer graphics algorithm, in all sorts of books and websites).
2. Take your polygon, and transform (rotate) copies of all the vertices in it so that your desired hatch lines would be horizontal.
3. Use your rasterizing algorithm to compute horizontal hatch line segments (at the appropriate intervals) for the transformed polygon.
4. Using the inverse of the transform you used before, transform the endpoints of your line segments back to the original coordinate system.
This used to be one of the questions at the entry exam for the applicants at my previous working place. :-)
The basic algorithm would be the following:
1. Calculate the boundaries of the polygon according to the hatch direction. (It's simply the bounding rectangle in case of horizontal/vertical hatch lines but may be smaller for diagonal hatching, for example.)
2. Within these bounds move the current scanline according to the hatch direction.
3. Calculate intersections of the scanline and the polygon.
4. If you are between two intersections, draw the line, otherwise move.
5. Repeat steps 2, 3 and 4 while within the bounds.
joghurt:
Getting there.., I had a look at the G.K.S libs. The gkfilc.f fortran subroutine is what I am looking for but in C, I think it would take for ever to translate it. I realy do need a robust concave/convex polygon hatch function in C, is there nothing out there?
NovaDenizen:
I need to hatch with vectors.
There are thousands of hatch fill implementations in C out there, I think. Just Google a bit if you don't want to write it yourself. However, the algorithm I wrote above is robust and it works for any (convex/concave) polygons and it's quite simple to do.
I've been searching for quite a long time with not much success (GKS was the closest).. have you any links?
I have found a cross hatch function in a book, but it doesn't seem to work, should I post this?
could you have a look?
As I was getting the source ready, I spotted a typo error, the function works fine, with one small reserve, if the hatch line passes through the end point of two connecting vectors then the hatch function fails, any ideas? should I stil post the source?,
many thanks "joghurt" & co. for the moral & tech support. I got 90% what I want!
Respect....
0
Featured Post
Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.
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â€¦
Summary:
This tutorial covers some basics of pointer, pointer arithmetic and function pointer.
What is a pointer:
A pointer is a variable which holds an address.Â This address might be address of another variable/address of devices/address of fuâ€¦