PDA

View Full Version : Help With Making an Arc/Parabola




mandude
Nov 19, 2009, 07:31 PM
hello, whoever can help me with this will know that they are jusus christ reincarnate. So im trying to make an arc/parabola that has 2 intersecting points obviously, and the highest point on this arc will be always always 50 pixes high. Now the first point the parabola crosses will always be the same point, (252,220) the second point its to be where ever i tap the screen. so to wrap things up i need a parabola, one point of intersection is always (252,220) the second is where ever the user taps the screen, with a height of always 50 pixels. thats not even half the problem. :) So far, heres my code... not working out too good :P
- (void)drawRect: (CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 5.0);
CGContextSetStrokeColorWithColor(context, currentColor.CGColor);

CGContextSetFillColorWithColor(context, currentColor.CGColor);

switch (shapeType) {
case kParabolaShape:
CGContextMoveToPoint(context, 252, 220);
CGContextAddArcToPoint(context 252, 220, firstTouch.x, firstTouch.y, 50.0);
CGContextStrokePath(context);
break;
}


Now once i get that to work right, i also need an image (image.png) to be animated and follow the arc/parabola that is created everytime the user taps. So when the user taps the screen, an arc 50 pixels high appears between where they tapped and (252,220) and then they see an image (image.png) move across the drawn parabola and then dissappear whoever can get this i love you


this is the basic idea of what it should be like:



newb16
Nov 20, 2009, 04:26 AM
hello, whoever can help me with this will know that they are jusus christ reincarnate. So im trying to make an arc/parabola that has 2 intersecting points obviously, and the highest point on this arc will be always always 50 pixes high.

Intersection with what? With the line (y=220) ? Height above what - about the same line (y=220) ?
Then, if it's an arc, it has limitations - if touch point is less than 100 pixels from the first 'intersection' point, you can't make an arc with such radius to have any point with spicified 'height' (above y=220 line).
The parabola is another story - I don't know if there are api methods other that building it from splines or line segments.


CGContextMoveToPoint(context, 252, 220);
CGContextAddArcToPoint(context 252, 220, firstTouch.x, firstTouch.y, 50.0);


First parameter of ArcToPoint with the current point defines a line - so they should not be equal.
Assuming d is distance from origin(252, 220) to touch point, and R is desired radius of arc, (R-50)**2 + (d/2)**2 == R**2
The height of point (H) in the first two arguments of ArcToPoint above that bse line is ( if we consider triangles composed of chord ( base line within the arc), radius to the origin point and vertical radius ) : (r-50)/(d/2) == (d/2)/H
Its x coordinate, obviously, it in the middle between the origin and the touch.