Calculate points for borders inside and outside of a polygon - ios

In my code I get some set of points that define a simple polygon. I need to draw the polygon itself, as well as a border inside and outside of it
If it was a rectangle, I could simply use CGRectInset() on iOS. However, it isn't a rectangle.
So I need an algorithm that provides me the inner and outer borders from a simple polygon.

Check out CGPathCreateCopyByStrokingPath.

Related

Figure out if points lays in area

Given and image and 4 corner points of an area inside the image, I want to figure out if a point p (x,y) lays inside the given area. The area is not necessarily in form of a rectangle, as the area is the result of a perspective projection of some other image.
For example:
Here I want to figure out if the pink point actually lays within the shape inside the image. In this case it does.
I was thinking about drawing an contour with drawContours and then using pointPolygonTest but I was wondering if there is an easier and more tailored way of doing it.

How to fill color along the edge within specific distance

I’m trying to fill color along the edge but I got stuck.
First, I have an image and I apply the sobel filter on it. After I calculate the gradient, I get an edge 2d array which contains the direction.
And now, I have no idea how to draw it.
The very first method that comes up to my mind is that I can check every pixel to see whether it’s on the edge and if yes then just make an intersection between the edge array and a circle(whose center is exactly that point), and run flood fill algorithm.
Here comes the problem, I don’t know how to intersect two-pixel array.
And the effect I want to get is like the image below.
the polygon represent the edge array and the red part is where I want to paint
See this draw, use morphological operation with disk structure element and masking: scheme

Is there an MKSquare in iOS?

I have a bunch of lat/long coordinates and I need to draw a square polygon around each one. Each square will be a set size (e.g. 50x50) with the coordinate in the centre. I see there is a MKCircle class but is there an MKSquare equivalent (I couldn't fine one but that doesn't mean there isn't) and if there isn't, any suggestions on how this could be achieved? I have done some searching and didn't produce any solid suggestions.
I would also like to make the square 3D as in if the map is tilted it would show a height kind of like buildings.
You can use MKPolygon for this. Simply provide four coordinates the correct distance from your center point and the four coordinates will form a square.

Multi Color Polygon in iOS

Hi I am trying to implement a polygon with a color gradient based on the color of each corner (the polygon is an overlay for a map). Up until now I have been using MKPolygon. Any Guidance will be appreciated.
Thanks,
To Achieve my result I wrote a for loop that iterated through all the points, which had a for loop inside that subtracted a value from the other points to make the polygon smaller and created a polygon this was done until the polygon was small enough for the view. This gave it a nice gradient and doing it for the other cornea with different colors gave the desired gradient of colors.

Common outline for two shapes drawn in drawRect: ObjectiveC

I have two shapes in a UIView - one, an ellipse and two, a triangle drawn using UIBezierPath. I need to draw the outline of these two shapes combined. How can I do it?
You can do an "outside" stroke (like stroke->outside in photoshop/pixelmator) by calling stroke to draw the outline and setting the inverse of your shapes as the clipping path first. To do the inverse of the clipping path see this answer: https://stackoverflow.com/a/10639523/461492 (read comments too).
So here are the steps:
Set the full area as the clipping path.
Call CGContextEOClip() for each of your shapes as described in the comments to the answer linked above.
Stroke your shapes.
This might not be exactly what you want - it will draw the stroke as normal but the whole interior (the fill area) of your shapes will not be drawn. So whereas the thickness of the stroke would normally extend within the interior of your shapes, and the internal angles of your stroke would normally have the correct corners (rounded/mitered) - in this case it would be more like you stroked the shapes then deleted the fill-area, or did an "outside" stroke in an image editing program.

Resources