Consider a line from point A (x,y) to B (p,q).
The method CGContextMoveToPoint(context, x, y);
moves to the point x,y and the method CGContextAddLineToPoint(context, p, q);
will draw the line from point A to B.
My question is, can I find the all points that the line cover?
Actually I need to know the exact point which is x points before the end point B.
Refer this image..
The line above is just for reference. This line may have in any angle. I needed the 5th point which is in the line before the point B.
Thank you
It's not so hard, translate your segment into a math line expression, x pixels may be translated into radius of a circe with center in B, make a system to find where they intercept, you get two solutions, take the point that is closer to A.
You should not think in terms of pixels. Coordinates are floating point values. The geometric point at
(x,y)
does not need to be a pixel at all. In fact you should think of pixels as being rectangles in your coordinate system.This means that "x pixels before the end point" does not really makes sense. If a pixel is a rectangle, "x pixels" is a different quantity if you move horizontally than it is if you move vertically. And if you move in any other direction it's even harder to decide what it means.
Depending on what you are trying to do it may or may not be easy to translate your concepts in pixel terms. It's probably better, however, to do the opposite and stop thinking in terms of pixels and translate all you are currently expressing in pixel terms into non pixel terms.
Also remember that exactly what a pixel is is system dependent and you may or may not, in general, be able to query the system about it (especially if you take into consideration things like retina displays and all resolution independent functionality).
Edit:
I see you edited your question, but "points" is not more precise than "pixels".
However I'll try to give you a workable solution. At least it will be workable once you reformulate your problem in the right terms.
Your question, correctly formulated, should be:
Given two points
A
andB
in a cartesian space and a distancedelta
, what are the coordinates of a pointC
such thatC
is on the line passing throughA
andB
and the length of the segment BC isdelta
?Here's a solution to that question:
You need to make sure that points A and B are not too close or the computations will be imprecise and the result will be different than you expect. That's what
epsilon
is supposed to do (you may or may not want to change the value ofepsilon
).Ideally a suitable value for
epsilon
is not related to the smallest number representable in adouble
but to the level of precision that adouble
gives you for values in the order of magnitude of the coordinates.I have hardcoded
epsilon
, which is a common way to define it's value as you generally know in advance the order of magnitude of your data, but there are also 'adaptive' techniques to compute anepsilon
from the actual values of the arguments (the coordinates of A and B and the delta, in this case).Also note that I have coded for legibility (the compiler should be able to optimize anyway). Feel free to recode if you wish.
This is the code you can use
Either you can follow this link also it will give you the detail description -
How to find a third point using two other points and their angle.
You can find out number of points whichever you want to find.