iphone: finding coordinate of CGPath - iphone

I have drawn an line graph (as an unclosed path) with 10 (x,y) points by using CGContextBeginPath, CGContextAddLineToPoint and CGContextMoveToPoint .
I would like to be able to retrieve the vertical coordinate (y) of the path where the user have given input of the horizontal coordinate (x) by touching the screen, so I can display further information about the graph. Any ideas on what is the best way to achieve this?
thanks

y = mx + b

Use CGPathGetCurrentPoint(CGPath *) method. Hope this helps.

NSLog(#"PATH: %#",CGRectCreateDictionaryRepresentation(CGPathGetPathBoundingBox(pathRef)));

Related

Property coordinates

I have 14,000 Property coordinates and want to move them to the (c)kerbside or (sidewalk) footpath.
Is their a way to do this?
Maybe the Property coordinates moved to the Closest road Boundaries (polyline?) +3metres
regards michael
You could try to fit a line to the street and then find a perpendicular line to the property coordinate. The place where the two interest should be what you need?

Adding a square polygon of a set size around a point using leaflet.js

Bit of a weird one I hope someone can help out with.
In leaflet, once the user has entered a lat/lng and added a point to the map I want to be able to also add a 10km square around that point.
I've tried looking around for a calculation to find the corners of the square x Km away but haven't dug anything up. But surely there's an easier way!
Does anyone have any thoughts? It'd be lovely to just say L.polygon then pass in a centre point and a square size.
Thanks,
Tayler
Initialize a L.Circle on your desired latitude/longitude with a radius of 5000 meters, grab the boundaries and use them to initialize a L.Rectangle:
new L.Rectangle(new L.Circle([0, 0], 5000).getBounds())

"Show" anchor point?

I'm using a custom image (which is 360 x 276 so not proportional) and I'm rotating it with an animation.
The anchor point is not just (0,.5) or (1,0), it's something like (.23423, .912314). Is there any way to show, where the anchor point currently is? Or setting it in InterfaceBuilder? Currently I'm just trying to reach the correct CGPoint by testing different values, but I didn't get the perfect one.
You cannot simple set it in IB, unfortunately. In your case, I would use some image processing application to find out at what coordinate you need the image to rotate and then do the math:
84,3228 / 360 = 0.24423
Not necessarily brilliant, but workable I would say.
This might help.
CGPoint anchorPosition = CGPointMake(
imageView.frame.origin.x + imageView.frame.size.width*anchorPoint.x,
imageView.frame.origin.y + imageView.frame.size.height*anchorPoint.y);
You can refer to http://disanji.net/iOS_Doc/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/Layers.html

finding the center point of the screen in a zoom view in iphone

I'm trying to add a box to the centre of the screen in a zoom view. E.g. if I move into an area of the content view and try using the offset coordinates, it becomes erratic if I zoom in or out. I can't seem to figure out the right mathematical formula for this.
If you are working with a UIView or one of it's subclasses. You'll always have a center property available for you. That property is a CGPoint and you can do something like this to test if it is the required result you seek:
CGPoint center = [YourUIViewOrSubclass center];
NSLog(#"Center x is '%f' and y is '%f', center.c, center.y);
I hope this helps you. Otherwise try and rephrase your question and include a little context.

clear part of UIImage

I've been doing some research on online for a project I'm doing but so far haven't been able to quite get it working. I want to be able to slide my finger over a UIImage and delete part of it, kind of like an eraser. I'm able to draw lines on the screen but can't figure out how to do this. Any help would be greatly appreciated.
Can you mask the image and when you draw on it, it adds the lines to the mask (in white, rest of mask is black) and then it should make those spots transparent
http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html
There are two parts to this problem-
a) Determining the curve along which the finger was moved
b) Drawing the curve (which is really a combination of short lines) with the white color
For part (a), have a look at UIPanGestureRecognizer. Using the touchesBegan: & touchesMoved methods, you will be notified every time the finger moves even the smallest distance, and the source and destination co-ordinates, say (x1, y1) & (x2, y2).
Part (b), As you know how to draw a line, now you need to draw a line from the source to the destination with the line's width (thickness) equal to the finger's. For that you can set the line's width using CGContextSetLineWidth.