"omegayen " <omegayen@ameritech.net> wrote in message <i6okpf$6ac$1@fred.mathworks.com>...
> Hi,
>
> I have a circle that I know the center of, I know the radius, and I know the number of points.
>
> hence I can use the draw a circle function http://www.mathworks.com/matlabcentral/fileexchange/2876
>
> I then want to divide up the circle into arcs of the same number of points. then I want to find the midpoint as in center of each of these arcs.
>
> Can someone help me out with this.
>
> For example if I have a center of (1.5, 0) a radius of the circle of 3, and 30 number of points
>
> then draw a circle function is (essentially)
>
> center=[1.5,0];
> radius=3;
> NOP=30;
>
> THETA=linspace(0,2*pi,NOP);
> RHO=ones(1,NOP)*radius;
> [X1,Y1] = pol2cart(THETA,RHO);
> X1=X1+center(1);
> Y1=Y1+center(2);
> plot(X1,Y1,'b.');
>
> I was then thinking of finding the midpoint of the chord connecting two of the points on the outside of the circle
>
> midpointx=(X1(1)+X1(2))/2;
> midpointy=(Y1(1)+Y1(2))/2;
>
> then calculating a line where the center of the circle intersects this midpoint of the chord
>
> slope=((midpointy-0)/(midpointx-1.5))
>
> y=slope*(tt-1.5)
>
> then see where that line intersects the arc. but yeah not exactly sure, thanks
- - - - - - - - - - -
That approach has some difficulties. One is that it doesn't automatically tell you which of the two possible arcs to find the midpoint on, the small one or the large one. Another difficulty is that if the arc is right at pi radians, your chord midpoint would fall directly onto the circle's center, so a line joining these two points would be indeterminate. A third is that on a vertical line your slope would be infinite and y would be inf times zero which gives a NaN.
One approach to get around such difficulties is the following. Let [x0,y0) be the center of the arc, (x1,y1) a point at one end of the arc, and (x2,y2) the point at the other end of the arc, with the understanding that the chosen arc extends in a counterclockwise direction from (x1,y1) to (x2,y2). Such an arc can have an angle anywhere from 0 to 2*pi radians. Then do the following to find the midpoint of that arc:
x10 = x1-x0; y10 = y1-y0;
x20 = x2-x0; y20 = y2-y0;
a = 1/2*mod(atan2(y20,x20)-atan2(y10,x10),2*pi); % Half arc angle
x = x0 + x10*cos(a) - y10*sin(a);
y = y0 + y10*cos(a) + x10*sin(a);
The point (x,y) will be the desired arc midpoint.
Roger Stafford
> Hi,
>
> I have a circle that I know the center of, I know the radius, and I know the number of points.
>
> hence I can use the draw a circle function http://www.mathworks.com/matlabcentral/fileexchange/2876
>
> I then want to divide up the circle into arcs of the same number of points. then I want to find the midpoint as in center of each of these arcs.
>
> Can someone help me out with this.
>
> For example if I have a center of (1.5, 0) a radius of the circle of 3, and 30 number of points
>
> then draw a circle function is (essentially)
>
> center=[1.5,0];
> radius=3;
> NOP=30;
>
> THETA=linspace(0,2*pi,NOP);
> RHO=ones(1,NOP)*radius;
> [X1,Y1] = pol2cart(THETA,RHO);
> X1=X1+center(1);
> Y1=Y1+center(2);
> plot(X1,Y1,'b.');
>
> I was then thinking of finding the midpoint of the chord connecting two of the points on the outside of the circle
>
> midpointx=(X1(1)+X1(2))/2;
> midpointy=(Y1(1)+Y1(2))/2;
>
> then calculating a line where the center of the circle intersects this midpoint of the chord
>
> slope=((midpointy-0)/(midpointx-1.5))
>
> y=slope*(tt-1.5)
>
> then see where that line intersects the arc. but yeah not exactly sure, thanks
- - - - - - - - - - -
That approach has some difficulties. One is that it doesn't automatically tell you which of the two possible arcs to find the midpoint on, the small one or the large one. Another difficulty is that if the arc is right at pi radians, your chord midpoint would fall directly onto the circle's center, so a line joining these two points would be indeterminate. A third is that on a vertical line your slope would be infinite and y would be inf times zero which gives a NaN.
One approach to get around such difficulties is the following. Let [x0,y0) be the center of the arc, (x1,y1) a point at one end of the arc, and (x2,y2) the point at the other end of the arc, with the understanding that the chosen arc extends in a counterclockwise direction from (x1,y1) to (x2,y2). Such an arc can have an angle anywhere from 0 to 2*pi radians. Then do the following to find the midpoint of that arc:
x10 = x1-x0; y10 = y1-y0;
x20 = x2-x0; y20 = y2-y0;
a = 1/2*mod(atan2(y20,x20)-atan2(y10,x10),2*pi); % Half arc angle
x = x0 + x10*cos(a) - y10*sin(a);
y = y0 + y10*cos(a) + x10*sin(a);
The point (x,y) will be the desired arc midpoint.
Roger Stafford