Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
I have looked everywhere for an algorithm that I can port to ICE for drawing circle arcs.
The only ones I can find are ~500 lines long, which would be too slow.

EDIT: This simple one requires floats:

Code:
def plotCirle (xc, yc, rad, start, end):
    theta = start
    while theta <= end:
        x = xc + rad * sin (theta)
        y = yc + rad * cos (theta)
        plot (x, y)
        theta = theta + 0.01


EDIT: I would like to be able to specify an exact radius

If someone can help me, that would be great.

Thanks,
You could just keep poking me: https://github.com/CE-Programming/toolchain/issues/146

But you can do everything with integers.
Floats arn't required, you could fixed point math. The trig function in Ice have a range of [-255, 255], and a full circle is (I think) 256 "degrees". Simply do all your math with your numbers inflated by 256 times, then devide 256. (So right before you get your "final" XY by adding your center X/Y to your sin/cos values, divide your sin/cos values by 256)
c4ooo wrote:
Floats arn't required, you could fixed point math. The trig function in Ice have a range of [-255, 255], and a full circle is (I think) 256 "degrees". Simply do all your math with your numbers inflated by 256 times, then devide 256. (So right before you get your "final" XY by adding your center X/Y to your sin/cos values, divide your sin/cos values by 256)

I may be wrong, but it's a bit trickier than that; it's really hard to divide the numbers to make the radius smaller. This is because ICE had no negatives, and it wraps around any "negatives" to past 16777216. So if I wanted a circle with a radius of less than 256 (that's how it is without multiplication or division), and I tried to divide any of the negative coordinates by a number, instead of giving me the correct value (16777...), It would give me the 16 million ish number divided by whatever. Despite all this, I whipped together a quick and inefficient program to draw an arc. I'll add it below in a few minutes one I get to my computer.
Yea, that's why Axe had a signed devision operation signified by a two devision symbols: '//'. Because Ice doesn't have this (but PT said it's planned), you would have to render only the first quadrant, and mirror it into other quadrants.

Alternatively you could take the absolute value and add the sign in later.
c4ooo wrote:
Alternatively you could take the absolute value and add the sign in later.

Yep, that's what mine does (sort of).

All right, here's my very quick code. I don't really have any time right now to optimize or make it remotely good, but here goes:

Code:
[i]ARC
Begin
0->B
255->C
160->X
120->Y
For(A,B,C)
   A>64 and A<192->CX
   A>128->CY
   A->CA
   If CX
      128-CA+256*(CA>128)->CA
   End
   If CY
      256-CA->CA
   End
   SetPixel((1-2*CX)*(cos(CA)/3)+X,(1-2*CY)*(sin(CA)/3)+Y)
   [i]Pause 100
End
Pause
det(1

Where B is the start of the arc in "degrees", C is the end, and X and Y are the coordinates. This can be modified to make it look/work better, but like I said, I don't have time. Also, you can replace the "/3"'s to resize the circle/ellipse. Hope this helps. I can explain later if needed.
The other is that if your circle had a small radius, he delta angle is going too small to get to a new pixel each iteration of the loop, so that you will calculate and plot pixels more then once, and if the radius is big enough you aren't going to have gaps between your pixels.

A better algorithm would be

Code:

For(x=0; x<radius; x++){
SetPixel(x,Sin(acos(x));
}

Or

Code:

For(x=0; x<radius; x++){
SetPixel(x,Sqrt(1 - x * x));
}
c4ooo wrote:
The other is that if your circle had a small radius, he delta angle is going too small to get to a new pixel each iteration of the loop, so that you will calculate and plot pixels more then once, and if the radius is big enough you aren't going to have gaps between your pixels.

A better algorithm would be

Code:

For(x=0; x<radius; x++){
SetPixel(x,Sin(acos(x));
}

Or

Code:

For(x=0; x<radius; x++){
SetPixel(x,Sqrt(1 - x * x));
}

Yep, you're right. As I said, it's inefficient. And that last one looks promising for use in ICE.
This algorithm is pretty cool:
Pi_Runner wrote:

Code:
[i]ARC
Begin
0->B
255->C
160->X
120->Y
For(A,B,C)
   A>64 and A<192->CX
   A>128->CY
   A->CA
   If CX
      128-CA+256*(CA>128)->CA
   End
   If CY
      256-CA->CA
   End
   SetPixel((1-2*CX)*(cos(CA)/3)+X,(1-2*CY)*(sin(CA)/3)+Y)
   [i]Pause 100
End
Pause
det(1

However, it is not exactly what I'm looking for.
I have optimized it a little bit, but there is no way to set an exact radius.
As I am having the user of my program draw the arc, I would like to make it a little more intuitive how to use it. (And this way just isn't as exact)
I have edited my original post to specify this.

Thanks,
calclover2514 wrote:
As I am having the user of my program draw the arc, I would like to make it a little more intuitive how to use it. (And this way just isn't as exact.

What would be useful to know now is what exactly you need. I might not be able to make it, but I'm sure there's someone who can. Some extra information would help define what it is you need the code to do.
Pi_Runner wrote:
calclover2514 wrote:
As I am having the user of my program draw the arc, I would like to make it a little more intuitive how to use it. (And this way just isn't as exact.

What would be useful to know now is what exactly you need. I might not be able to make it, but I'm sure there's someone who can. Some extra information would help define what it is you need the code to do.

I would like an algorithm that will draw an arc when given the x,y coordinates of the middle of the circle, the beginning and end angles in degrees, and the radius in pixels.
I would also like for it to be a connected line rather than a series of points.
I hope this helps.

Thanks,
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement