Hello all,
I am trying to graph a section of a circle into an array. I have been trying to wrap my head around [sin] and [cos] but none of my configurations get results. If you had a circle with radius 100 with a center at (0, 0) I'm trying to get the upper right quadrant (positive x and positive y). The start point being (100,0) and the end point being (0,100).
Any ideas on moving forward?
Tyler
On Fri, 8 Apr 2011, Tyler Leavitt wrote:
I am trying to graph a section of a circle into an array. I have been trying to wrap my head around [sin] and [cos] but none of my configurations get results. If you had a circle with radius 100 with a center at (0, 0) I'm trying to get the upper right quadrant (positive x and positive y). The start point being (100,0) and the end point being (0,100).
Any ideas on moving forward?
use angles between 0 and pi/2 = 1.5708
putting those into [cos] and [sin] will give you values for a circle of radius 1 at (0,0). For different radiuses you apply [*] after that.
quadrants and clockwiseness depend on which axis uses [cos], which axis uses [sin], and which direction of each axis is positive. There are several standards for those things.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
By the way, there's a way to draw a circle using nothing but addition: http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
Implementing this in Pd is completely impractical, but it's fun to think about. Cheers, Peter
On Sat, Apr 9, 2011 at 2:12 AM, Mathieu Bouchard matju@artengine.ca wrote:
On Fri, 8 Apr 2011, Tyler Leavitt wrote:
I am trying to graph a section of a circle into an array. I have been
trying to wrap my head around [sin] and [cos] but none of my configurations get results. If you had a circle with radius 100 with a center at (0, 0) I'm trying to get the upper right quadrant (positive x and positive y). The start point being (100,0) and the end point being (0,100).
Any ideas on moving forward?
use angles between 0 and pi/2 = 1.5708
putting those into [cos] and [sin] will give you values for a circle of radius 1 at (0,0). For different radiuses you apply [*] after that.
quadrants and clockwiseness depend on which axis uses [cos], which axis uses [sin], and which direction of each axis is positive. There are several standards for those things.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
Pd-list@iem.at mailing list UNSUBSCRIBE and account-management -> http://lists.puredata.info/listinfo/pd-list
On Sat, 9 Apr 2011, Peter Brinkmann wrote:
By the way, there's a way to draw a circle using nothing but addition: http://en.wikipedia.org/wiki/Midpoint_circle_algorithm Implementing this in Pd is completely impractical, but it's fun to think about.
It's not strictly the same thing, because by using sin and cos, you are ensuring equal distance between points at infinite resolution, and you are ensuring equal angles everywhere too.
With the midpoint circle algorithm, instead, you are ensuring that all points are one pixel apart, when using a limited resolution. The pixels are considered one pixel apart when sharing an edge or corner. This is related to http://en.wikipedia.org/wiki/Maximum_norm
So, it depends on whether you're trying to draw something continuous-looking on a pixel display.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On Sat, Apr 9, 2011 at 7:32 PM, Mathieu Bouchard matju@artengine.ca wrote:
On Sat, 9 Apr 2011, Peter Brinkmann wrote:
By the way, there's a way to draw a circle using nothing but addition:
http://en.wikipedia.org/wiki/Midpoint_circle_algorithm Implementing this in Pd is completely impractical, but it's fun to think about.
It's not strictly the same thing, because by using sin and cos, you are ensuring equal distance between points at infinite resolution, and you are ensuring equal angles everywhere too.
With the midpoint circle algorithm, instead, you are ensuring that all points are one pixel apart, when using a limited resolution. The pixels are considered one pixel apart when sharing an edge or corner. This is related to http://en.wikipedia.org/wiki/Maximum_norm
So, it depends on whether you're trying to draw something continuous-looking on a pixel display.
Sure, but in this case the goal was to draw a section of a circle in an array, and the midpoint algorithm would be a good choice if implementing it in Pd weren't so complex. Anyway, it doesn't really matter, I just like Bresenham-style algorithms. Cheers, Peter
I've not had any real success using the formulas with [sin] and [cos]... maybe I'm missing something here. The only solution that I've gotten to work is the midpoint circle algorithm with Peter's patch.
I've included a patch to show where I'm struggling... When the arc gets drawn with bigger radiuses (and bigger arrays) there are a lot of indexes with no value so it's constantly jumping between 0 and the correct value. Is there a way to get pd to approximate the values in between (more or less an average between plotted points)?
Thanks so far for all the help Tyler
On Fri, Apr 8, 2011 at 11:12 PM, Mathieu Bouchard matju@artengine.cawrote:
On Fri, 8 Apr 2011, Tyler Leavitt wrote:
I am trying to graph a section of a circle into an array. I have been
trying to wrap my head around [sin] and [cos] but none of my configurations get results. If you had a circle with radius 100 with a center at (0, 0) I'm trying to get the upper right quadrant (positive x and positive y). The start point being (100,0) and the end point being (0,100).
Any ideas on moving forward?
use angles between 0 and pi/2 = 1.5708
putting those into [cos] and [sin] will give you values for a circle of radius 1 at (0,0). For different radiuses you apply [*] after that.
quadrants and clockwiseness depend on which axis uses [cos], which axis uses [sin], and which direction of each axis is positive. There are several standards for those things.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
Ok well now I have really attached the patch...
On Sun, Apr 10, 2011 at 7:12 AM, Tyler Leavitt thecryoflove@gmail.comwrote:
I've not had any real success using the formulas with [sin] and [cos]... maybe I'm missing something here. The only solution that I've gotten to work is the midpoint circle algorithm with Peter's patch.
I've included a patch to show where I'm struggling... When the arc gets drawn with bigger radiuses (and bigger arrays) there are a lot of indexes with no value so it's constantly jumping between 0 and the correct value. Is there a way to get pd to approximate the values in between (more or less an average between plotted points)?
Thanks so far for all the help Tyler
On Fri, Apr 8, 2011 at 11:12 PM, Mathieu Bouchard matju@artengine.cawrote:
On Fri, 8 Apr 2011, Tyler Leavitt wrote:
I am trying to graph a section of a circle into an array. I have been
trying to wrap my head around [sin] and [cos] but none of my configurations get results. If you had a circle with radius 100 with a center at (0, 0) I'm trying to get the upper right quadrant (positive x and positive y). The start point being (100,0) and the end point being (0,100).
Any ideas on moving forward?
use angles between 0 and pi/2 = 1.5708
putting those into [cos] and [sin] will give you values for a circle of radius 1 at (0,0). For different radiuses you apply [*] after that.
quadrants and clockwiseness depend on which axis uses [cos], which axis uses [sin], and which direction of each axis is positive. There are several standards for those things.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On 10/04/11 15:12, Tyler Leavitt wrote:
I've not had any real success using the formulas with [sin] and [cos]... maybe I'm missing something here. The only solution that I've gotten to work is the midpoint circle algorithm with Peter's patch.
A circle centered at the origin is implicitly[1] described by:
x^2 + y^2 = r^2
Rearranging this gives:
y = +/- sqrt(r^2 - x^2) for -r <= x <= r
Hopefully this more useful for your purposes than the parametric form:
(x,y) = (cos(t), sin(t)) for -PI <= t <= PI
Should be much simpler to implement than an optimized-for-integers Bresenham-style implementation.
Relatedly[2] I like this function too:
f(x,t) = sqrt((t^2)+(x^2)*(2*t+1))-t for -1 <= x <= 1 and 0 <= t
[1] http://en.wikipedia.org/wiki/Circle#Cartesian_coordinates [2] http://en.wikipedia.org/wiki/Conic_section
On Sun, 10 Apr 2011, Tyler Leavitt wrote:
I've not had any real success using the formulas with [sin] and [cos]...
I don't know why, but I had assumed that you wanted to plot something "parametrically", such as a path drawn from x(t) and y(t) functions, instead of a y(x) function. I was reading too fast.
For a y(x) function, sqrt(r*r-x*x) is the formula to use.
That is related to the fact that sqrt(1-x*x) = sin(acos(x)) = cos(asin(x)) where asin is anti-sin and acos is anti-cos.
It's also related to Pythagoras' theorem x*x + y*y = r*r which is also sin(t)*sin(t) + cos(t)*cos(t) = 1.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
Using the sqrt(r^2-x^2) formula I get the same results as with the [sin], [cos]. Maybe I'm just implementing it wrong, but I can't figure out why it's not plotting the correct y values...
Here's the patch I sent before with my implementation of the sqrt(r^2 - x^2)
On Sun, Apr 10, 2011 at 8:52 AM, Mathieu Bouchard matju@artengine.cawrote:
On Sun, 10 Apr 2011, Tyler Leavitt wrote:
I've not had any real success using the formulas with [sin] and [cos]...
I don't know why, but I had assumed that you wanted to plot something "parametrically", such as a path drawn from x(t) and y(t) functions, instead of a y(x) function. I was reading too fast.
For a y(x) function, sqrt(r*r-x*x) is the formula to use.
That is related to the fact that sqrt(1-x*x) = sin(acos(x)) = cos(asin(x)) where asin is anti-sin and acos is anti-cos.
It's also related to Pythagoras' theorem x*x + y*y = r*r which is also sin(t)*sin(t) + cos(t)*cos(t) = 1.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
On Sun, 10 Apr 2011, Tyler Leavitt wrote:
Using the sqrt(r^2-x^2) formula I get the same results as with the [sin], [cos]. Maybe I'm just implementing it wrong, but I can't figure out why it's not plotting the correct y values... Here's the patch I sent before with my implementation of the sqrt(r^2 - x^2)
The x is supposed to be the right-inlet of [tabwrite], not the left-inlet. Otherwise you will write many values in the same location, while skipping many other locations.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC
Heh... wow. Thanks for pointing out my negligence and all the help up to this point =)
Tyler
On Sun, Apr 10, 2011 at 9:59 AM, Mathieu Bouchard matju@artengine.cawrote:
On Sun, 10 Apr 2011, Tyler Leavitt wrote:
Using the sqrt(r^2-x^2) formula I get the same results as with the [sin],
[cos]. Maybe I'm just implementing it wrong, but I can't figure out why it's not plotting the correct y values... Here's the patch I sent before with my implementation of the sqrt(r^2 - x^2)
The x is supposed to be the right-inlet of [tabwrite], not the left-inlet. Otherwise you will write many values in the same location, while skipping many other locations.
| Mathieu Bouchard ---- tél: +1.514.383.3801 ---- Villeray, Montréal, QC