Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
midpoint as in center of an arc

Subject: midpoint as in center of an arc

From: omegayen

Date: 14 Sep, 2010 20:09:19

Message: 1 of 3

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

Subject: midpoint as in center of an arc

From: Roger Stafford

Date: 15 Sep, 2010 08:12:05

Message: 2 of 3

"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

Subject: midpoint as in center of an arc

From: Roger Stafford

Date: 15 Sep, 2010 19:07:07

Message: 3 of 3

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i6pv4l$opn$1@fred.mathworks.com>...
> .......
> 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
- - - - - - - - -
  Here is an alternate method which doesn't use trigonometric functions though it requires more lines of code. Again (x0,y0), (x1,y1), and (x2,y2) are defined as before.

 x10 = x1-x0; y10 = y1-y0;
 x20 = x2-x0; y20 = y2-y0;
 d = sqrt((x20-x10)^2+(y20-y10)^2);
 e = sqrt((x20+x10)^2+(y20+y10)^2);
 c = 2*sqrt(d^2+e^2);
 a = e/c*sign(x10*y20-y10*x20);
 b = d/c;
 x = x0 + a*(x20+x10) - b*(y20-y10);
 y = y0 + a*(y20+y10) + b*(x20-x10);

Again (x,y) is the required arc midpoint.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us