Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Known details

Circle radius r

Origin (x,y)

starting point in circumference say (u,v)

I want to know the next point to be drawn on the circle circumference

image

I do need to draw this point by point forming arc of this circle .

Help me out of this. I have checked some post in here itself but nothing seems working for me

share|improve this question
    
What do you mean by continuous? a circumference is dense (there are infinite many points between any two points) –  Kevin Dec 14 '13 at 6:42
    
Also, solid angle applies to a sphere (or 3D angle if that helps). On a circumference, only angle makes sense –  Kevin Dec 14 '13 at 6:44
    
continous points i refer by integer , Not in float, So that it would be limited isnt it ? –  Arju Dec 14 '13 at 6:58
1  
Please, update your question so that it reflects your specific needs and the progress you have made. Make sure to include that $u$, $v$, $x$, $y$ (and maybe $r$?) are integers and that you are looking for a coding approach (that's what your comments suggest) –  Kevin Dec 17 '13 at 18:09

2 Answers 2

There is undoubtedly a good computationally efficient answer. This is not it. Let us suppose you are going counterclockwise. Choose a quite small angle $\theta$, maybe $\frac{1}{10}$ of a degree. You will have to experiment to see what gives smooth motion.

In principle the next point is $$(u_1,v_1)=(u\cos\theta-v\sin\theta, u\sin\theta+v\cos\theta).$$ Note that $\cos\theta$ and $\sin\theta$ can be precomputed, so the calculation is cheap. What has been done here is multiplication by a rotation matrix.

The problem is that tiny errors will accumulate. So every so often, or perhaps every time, force the point to be on the circle by computing $u_1$ as above, and letting $v_1$ be $\pm\sqrt{r^2-u_1^2}$. You will have to pick the appropriate sign, which most of the time will be the sign of $v$, but some code will have to be written for sign transitions.

But undoubtedly the problem has been solved in a more efficient way many times.

share|improve this answer
    
Any way, How can we draw this based on origin? Since it is not using any origin co-ordinates –  Arju Dec 14 '13 at 7:04
    
I assumed the origin was at $(0,0)$. If it is at $(a,b)$, modify as follows. Let your initial point be $(p,q)$. (I am changing the name to preserve what I wrote.) Let $u=p-a$, $v=p-b$. Calculate $(u_1,v_1)$ as in the post, and let $(p_1,q_1)=(u_1+a, v_1+b)$. Then $(p_1,q_1)$ is your next point. –  André Nicolas Dec 14 '13 at 7:09
    
Yeah, thanks @Andre, I will try it out . –  Arju Dec 14 '13 at 7:15
1  
The method I have described will, in principle, work. However, computational efficiency is extremely important. If you don't get suitable answers on this site, you might consider asking on a computation site, where there will be real experts in game programming. –  André Nicolas Dec 14 '13 at 7:18

This is one possible way of coding it. I will use the form [returns] = functionname(arguments) so that you understand what is returned and what are the arguments.

[xn, qn] = nextpoint(xc, qc, xo, r)
// xc = current point in format (x,y)
// qc = current quadrant, can take values 1,2,3, or 4
// xo = origin coordinates in format (x,y)
// r  = radius (since there aren't any specifics, I am assuming it can be non-integer)
// xn = next point
// qn = next quadrant
  if (qc == 1)  // what points might be next depending on the quadrant of the current point
    g1 = (-1, 0)
    g2 = ( 0, 1)
  else if (qc == 2)
    g1 = (-1, 0)
    g2 = ( 0,-1)
  else if (qc == 3)
    g1 = ( 1, 0)
    g2 = ( 0,-1)
  else if (qc == 4)
    g1 = ( 1, 0)
    g2 = ( 0, 1)
  end
  g3 = g1 + g2
  g1 = xc + g1
  g2 = xc + g2
  g3 = xc + g3
  xn = from {g1,g2,g3} the one with smallest residual(gi,xo,r)
  if (xn.x == xo.x OR xn.y == xo.y)
    qn = qc + 1
  else
    qn = qc
  end

The idea here is to avoid expensive trigonometric functions by comparing values. The performance advantage will depend on the language and compiler you use.

For residual, you can take a measure of how close the lattice point is to the actual circumference $$r_i=|(g_i-x_o)\cdot(g_i-x_o) - r^2|$$

And you can use the previous function like

[listofpoints] = getcircumference(xo,r)
  xco = xo + (round(r),0)
  qco = 1
  [xc, qc] = nexpoint(xco, qco, xo, r)
  listofpoints = {xc}
  while (xc different from xco)
    [xc, qc] = nextpoint(xc, qc, xo, r)
    append xc to listofpoints
  end

This worked for me in Mathematica and Matlab

share|improve this answer
    
I think this is a tough method than above –  Arju Dec 18 '13 at 4:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.