How to draw variable-width UIBezierPath? - iphone

I'm wondering how I should go about drawing a uibezierpath where the stroke width peaks at the center of the arc. Here's an example of what I mean:
Either I have to go through each point when drawing, and set the stroke width accordingly, or there's an easier way. Can anyone point me in the right direction?
Thanks

You can just draw the two outer paths with no stroke, join them, and then fill in the space between them.

Another way to try this if you're interested:
I ended up getting this to work by creating a loop to draw a couple hundred line segments, and changing the line width accordingly during the draw loop.
To adjust the line width I used the following function: MAX_WIDTH * sinf(M_PI * (i/NUMBER_OF_SEGMENTS)
Looks great and no performance issues as far as I can tell. Worked out particularly well because I already had a list of the points to use on the curve. For other cases I'm guessing it would be better to use sosborn's method.

Related

Spacing between heatmap point

I tried to customise leaflet heatmap.js to render rectangles to generate a heatmap. I was doing good so far. But, there are spacing in between rectangles that I can't get rid of. As in the picture.
heatmap
Solutions that I tried: turn off antialiasing, add offset. While adding offset remove the space, it creates an area with "blended color" which I don't want to have. I wonder if there is a solution to remove the gap or remove the blending color in heatmap.js.
Thanks and regards.
Turn out it is precision problem of the leaflet latlong to screen coordinate function. I have fixed it by recalculate the coordinate.

If I have 4 coordinates making a rectangle, how can I color in that area?

I have 4 coordinates assigned to variables, so I would just like to colour in the rectangle that is created from these variables. I tried the fill function, but I cant gather much information from the example.
When I try to use:
fill(bottom left point, top right point,'g')
the figure it makes only shows a line between those points, and doesn't colour in the entire area.
I'm using MATLAB R2019b, if that helps.
Also, if its possible to fill the rectangle with a pattern instead, please let me know aswell.
Thanks in advance

How to change constraint size in pymunk?

I found out how to change the colour of constraints:
draw_options = pymunk.pygame_util.DrawOptions(screen)
draw_options.constraint_color = 200,200,200
But when drawing small objects, the size of the constraint appears to be too large and makes it look bad.
Is there a way to reduce the size of those pin joints? Instead of a radius of 5 pixels, I'd prefer 1 or 2 pixel radius joints/constraints.
An alternative was to make it partly transparent, but adding an alpha component to the colour doesn't seem to work.
draw_options.constraint_color = 200,200,200,50
Unfortunately the debug draw color for constraints doesnt work. https://github.com/viblo/pymunk/issues/160
But in general if you want special drawing its probably easiest to do it yourself. Its mainly meant for debugging and quick prototyping, so if you need more than whats included try drawing it yourself instead. There are some examples that does custom drawing and does not depend on the debug draw code.

Expand line to a polygon

I would like to expand a line to a wider polygon. Add 10 meter on both sides of the line for example.
Here is an example of what I would like
Take this line
And expand it to a wider polygon, like this
I did this manually, is there a way to do this automaticly?
Changing the KML or using a program?
Thanks
Vincent
Depending on how accurate you need this – this is not trivial.
One possible algorithm could be:
for each segment do
expand segment to rectangle with width 2r
targetShape.join(rectangle)
next
for each point do
expand point to circle with radius r
targetShape.join(circle)
next
targetShape.outerHull(precision)
Each single line in this routine is tricky and depends on your expectations.
You could leave out the circles and instead make the rectangles longer, but this wil not work on sharp turns.
All of this involves ugly calculations to figure orthogonal lines etc.
You could try it in an graphic tool, gimp or inkskape :-)

CGContextMoveToPoint before CGContextShowText call

Does CGContextMoveToPoint work with CGContextShowText? I'm trying to draw to a PDF. Without any translating of the CTM, if I draw text, I see it in the bottom left side of the screen. Then I try to move to point (100,100), and the text is still there. But if I translate the CTM to position 100, 100, then I see the text at that point. Does CGContextMoveToPoint work with CGContextShowText? Otherwise it seems like I translate my CTM, then I need to make the reverse translation, then move it somewhere else to draw other text (like if I were doing a title, and then starting a paragraph). Thanks!
You need to use CGContextSetTextPosition() instead. I don't know why Quartz keeps different positions for text and graphics, but that's the way it is.