[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rmagick and circles

shawn bright

11/29/2008 7:45:00 PM

Hey there all,

I am using RMagick to draw some circles.
what i need though is a math formula to give me a pair of plot points
for an angle.

Say a circle is 40 x 40 on a sheet of graph paper.
this would put the center of the circle at x=20, y=20
and it would make the radius = 20.

now, i need to be able to pass in a number like say, 20 degrees and
return the x and y plots of this on the circle.

i know, more a math problem than ruby, but i could use any suggestions.

thanks,
shawn

4 Answers

Oliver Burghard

11/29/2008 8:35:00 PM

0

Hey,

I am not sure what you want. If you only want one point it is easy:

x = x_0 + radius * Math.cos(angle * 2.0 * Math::PI / 360.0)
y = y_0 + radius * Math.sin(angle * 2.0 * Math::PI / 360.0)

This is for the angle in degrees. Like this you can get any point on the
circle. Now if you want to get the points of an arc you could just
increase the angle a bit at a time and plot the points. But that would
not be a very nice circle and would be slow.

An option would be to get a starting point with the formula above and
then iterate with x**2 + y**2 = r**2. For example in the first part of
the circle between 0 and 45 degrees y is growing faster than x.

You would start with an y and increase it once by one.
( leave away the translation for easiness )

y' <- y + 1
x' <- sqrt( r**2 - (y+1)**2 ) = sqrt( r**2 - y**2 -2*y - 1)
= sqrt( x**2 - 2 * y - 1)

Hope it gives some ideas.

Oliver

Am Sonntag, den 30.11.2008, 04:45 +0900 schrieb shawn bright:
> Hey there all,
>
> I am using RMagick to draw some circles.
> what i need though is a math formula to give me a pair of plot points
> for an angle.
>
> Say a circle is 40 x 40 on a sheet of graph paper.
> this would put the center of the circle at x=20, y=20
> and it would make the radius = 20.
>
> now, i need to be able to pass in a number like say, 20 degrees and
> return the x and y plots of this on the circle.
>
> i know, more a math problem than ruby, but i could use any suggestions.
>
> thanks,
> shawn
>


shawn bright

11/29/2008 8:48:00 PM

0

This is great, thanks Oliver.
One question,

what is meant by x_0 and y_0, are those the plot points for the center
of the graph?
thanks.
shawn

On Sat, Nov 29, 2008 at 2:34 PM, Oliver Burghard <OliverBurghard@web.de> wrote:
> Hey,
>
> I am not sure what you want. If you only want one point it is easy:
>
> x = x_0 + radius * Math.cos(angle * 2.0 * Math::PI / 360.0)
> y = y_0 + radius * Math.sin(angle * 2.0 * Math::PI / 360.0)
>
> This is for the angle in degrees. Like this you can get any point on the
> circle. Now if you want to get the points of an arc you could just
> increase the angle a bit at a time and plot the points. But that would
> not be a very nice circle and would be slow.
>
> An option would be to get a starting point with the formula above and
> then iterate with x**2 + y**2 = r**2. For example in the first part of
> the circle between 0 and 45 degrees y is growing faster than x.
>
> You would start with an y and increase it once by one.
> ( leave away the translation for easiness )
>
> y' <- y + 1
> x' <- sqrt( r**2 - (y+1)**2 ) = sqrt( r**2 - y**2 -2*y - 1)
> = sqrt( x**2 - 2 * y - 1)
>
> Hope it gives some ideas.
>
> Oliver
>
> Am Sonntag, den 30.11.2008, 04:45 +0900 schrieb shawn bright:
>> Hey there all,
>>
>> I am using RMagick to draw some circles.
>> what i need though is a math formula to give me a pair of plot points
>> for an angle.
>>
>> Say a circle is 40 x 40 on a sheet of graph paper.
>> this would put the center of the circle at x=20, y=20
>> and it would make the radius = 20.
>>
>> now, i need to be able to pass in a number like say, 20 degrees and
>> return the x and y plots of this on the circle.
>>
>> i know, more a math problem than ruby, but i could use any suggestions.
>>
>> thanks,
>> shawn
>>
>
>
>

shawn bright

11/29/2008 11:36:00 PM

0

Thanks much
tinkered around with my numbers in your formula, and it worked.

shawn

On Sat, Nov 29, 2008 at 2:48 PM, shawn bright <nephish@gmail.com> wrote:
> This is great, thanks Oliver.
> One question,
>
> what is meant by x_0 and y_0, are those the plot points for the center
> of the graph?
> thanks.
> shawn
>
> On Sat, Nov 29, 2008 at 2:34 PM, Oliver Burghard <OliverBurghard@web.de> wrote:
>> Hey,
>>
>> I am not sure what you want. If you only want one point it is easy:
>>
>> x = x_0 + radius * Math.cos(angle * 2.0 * Math::PI / 360.0)
>> y = y_0 + radius * Math.sin(angle * 2.0 * Math::PI / 360.0)
>>
>> This is for the angle in degrees. Like this you can get any point on the
>> circle. Now if you want to get the points of an arc you could just
>> increase the angle a bit at a time and plot the points. But that would
>> not be a very nice circle and would be slow.
>>
>> An option would be to get a starting point with the formula above and
>> then iterate with x**2 + y**2 = r**2. For example in the first part of
>> the circle between 0 and 45 degrees y is growing faster than x.
>>
>> You would start with an y and increase it once by one.
>> ( leave away the translation for easiness )
>>
>> y' <- y + 1
>> x' <- sqrt( r**2 - (y+1)**2 ) = sqrt( r**2 - y**2 -2*y - 1)
>> = sqrt( x**2 - 2 * y - 1)
>>
>> Hope it gives some ideas.
>>
>> Oliver
>>
>> Am Sonntag, den 30.11.2008, 04:45 +0900 schrieb shawn bright:
>>> Hey there all,
>>>
>>> I am using RMagick to draw some circles.
>>> what i need though is a math formula to give me a pair of plot points
>>> for an angle.
>>>
>>> Say a circle is 40 x 40 on a sheet of graph paper.
>>> this would put the center of the circle at x=20, y=20
>>> and it would make the radius = 20.
>>>
>>> now, i need to be able to pass in a number like say, 20 degrees and
>>> return the x and y plots of this on the circle.
>>>
>>> i know, more a math problem than ruby, but i could use any suggestions.
>>>
>>> thanks,
>>> shawn
>>>
>>
>>
>>
>
>

Oliver Burghard

11/30/2008 1:09:00 AM

0

Yes, x_0 and y_0 are the coordinates of the center of the circle.


I am glad if I could help you. :)

Oliver


Am Sonntag, den 30.11.2008, 08:35 +0900 schrieb shawn bright:
> Thanks much
> tinkered around with my numbers in your formula, and it worked.
>
> shawn
>
> On Sat, Nov 29, 2008 at 2:48 PM, shawn bright <nephish@gmail.com> wrote:
> > This is great, thanks Oliver.
> > One question,
> >
> > what is meant by x_0 and y_0, are those the plot points for the center
> > of the graph?
> > thanks.
> > shawn
> >
> > On Sat, Nov 29, 2008 at 2:34 PM, Oliver Burghard <OliverBurghard@web.de> wrote:
> >> Hey,
> >>
> >> I am not sure what you want. If you only want one point it is easy:
> >>
> >> x = x_0 + radius * Math.cos(angle * 2.0 * Math::PI / 360.0)
> >> y = y_0 + radius * Math.sin(angle * 2.0 * Math::PI / 360.0)
> >>
> >> This is for the angle in degrees. Like this you can get any point on the
> >> circle. Now if you want to get the points of an arc you could just
> >> increase the angle a bit at a time and plot the points. But that would
> >> not be a very nice circle and would be slow.
> >>
> >> An option would be to get a starting point with the formula above and
> >> then iterate with x**2 + y**2 = r**2. For example in the first part of
> >> the circle between 0 and 45 degrees y is growing faster than x.
> >>
> >> You would start with an y and increase it once by one.
> >> ( leave away the translation for easiness )
> >>
> >> y' <- y + 1
> >> x' <- sqrt( r**2 - (y+1)**2 ) = sqrt( r**2 - y**2 -2*y - 1)
> >> = sqrt( x**2 - 2 * y - 1)
> >>
> >> Hope it gives some ideas.
> >>
> >> Oliver
> >>
> >> Am Sonntag, den 30.11.2008, 04:45 +0900 schrieb shawn bright:
> >>> Hey there all,
> >>>
> >>> I am using RMagick to draw some circles.
> >>> what i need though is a math formula to give me a pair of plot points
> >>> for an angle.
> >>>
> >>> Say a circle is 40 x 40 on a sheet of graph paper.
> >>> this would put the center of the circle at x=20, y=20
> >>> and it would make the radius = 20.
> >>>
> >>> now, i need to be able to pass in a number like say, 20 degrees and
> >>> return the x and y plots of this on the circle.
> >>>
> >>> i know, more a math problem than ruby, but i could use any suggestions.
> >>>
> >>> thanks,
> >>> shawn
> >>>
> >>
> >>
> >>
> >
> >
>