Draw polygon with color per vertex - ios

I am wondering if there is a way to draw a polygon on top of a MKMapView where each vertex in the polygon could potentially have a different color. The triangles of the polygon would correctly blend the colors together when rendered.
I know I can do this with OpenGL, but I would like to try to use CoreGraphics or a drawing function of MapKit first, as I don't know how well OpenGL works on top of a MKMapView.
I know there is support to fill a polyline with a gradient. Is there a similar way to fill a polygon/triangle with multiple gradients to achieve the desired effect?

Related

How to draw a textured rectangle with Metal

I'm looking for a most efficient way of drawing a 2-dimensional background in metal. This requires rendering a textured rectangle.
The basic geometry example shows an example on how to draw a triangle. Is there an easy and non-bloated way to draw a rectangle (a polygon with 4 corners)?
The Basic Texturing sample draws a textured rectangle

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.

Draw line between two points (x1,y1,z1) to (x2,y2,z2)

I know how to draw line on 2d surface.But I can't find a way to draw a line in space.
I have wrote a demo
and now I want to draw line in space.
and finish it like this:
I have finished the 2d surface rotate in space use CATransform3D already. But I don't know how to draw line in space.
Thanks a lot.
Normal drawing on iOS is 2D. Core Animation is "2.5D", where it can draw flat images with fake 3D perspective. It doesn't let you "draw in space."
If you want real 3D perspective drawing you should use OpenGL, SceneKit, Metal, or some other 3D API.
Your trying to draw a 3d image on a 2d surface. Therefore you need some sort of mapping
https://en.m.wikipedia.org/wiki/3D_projection
Has some options for you. Orthographic projection is probably what you want though
https://upload.wikimedia.org/math/8/3/a/83a402b37056afa1dd4c8d706a9a2d75.png
Is the equation you would want to use where s is a scaling factor and c is an offset

GL_LINE_STRIP - Using Textures ? iOS GLKit

Is it possible in OpenGL ES 2.0 to use GL_LINE_STRIP to draw a shape and then apply a texture to that shape ?
E.g if I draw a triangle can I then apply a triangle texture ?
GL_LINE_STRIP draws only lines. If you want polygons filled in (whether with color, lighting, or texturing), you need one of the solid polygon modes: GL_TRIANGLES, GL_TRIANGLE_STRIP, or GL_TRIANGLE_FAN.
If you want to both fill and stroke your polygons, you'll need two draw calls, one with each mode. And if you're using depth testing, you'll probably want to look into glPolygonOffset to avoid z-fighting.

Fill polygon shape with color in Corona SDK

I need to draw shape filled with special color in Corona SDK.
I'm trying draw vector map, where shapes will be as buildings.
The problem is object retuned by display.newLine() don't have setFillColor() method.
So, vector shape is empty (I see background through it), only stroke color can be changed via line:setColor().
How can I fill polygon shape with color?
Thanks.
There are a few polygon fill algorithms.
Have a read here :
http://alienryderflex.com/polygon_fill/
http://www.siggraph.org/education/materials/HyperGraph/scanline/outprims/polygon6.htm
And there is a nice implementation in Code Exchange!
http://developer.anscamobile.com/code/polygon-fill-and-point-polygon-detection

Resources