CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2013

    Connecting Circles C++/Excel

    This is quite complicated to explain, so I will do my best, sorry if there is anything I missed out, let me know and I will rectify it.

    My question is, I have been tasked to draw this shape,

    ![Crescent Moon](http://www.learnersdictionary.com/art/ld/crescent.gif)

    This is to be done using C++ to write code that will calculate the points on this shape.

    Important details.

    User Input - Centre Point (X, Y), number of points to be shown, Font Size (influences radius)

    Output - List of co-ordinates on the shape.

    The overall aim once I have the points is to put them into a graph on Excel and it will hopefully draw it for me, at the user inputted size!

    I know that the maximum Radius is 165mm and the minimum is 35mm. I have decided that my base [Font Size][1] shall be 20. I then did some thinking and came up with the equation.

    Radius = (Chosen Font Size/20)*130. This is just an estimation, I realise it probably not right, but I thought it could work at least as a template.

    I then decided that I should create two different circles, with two different centre points, then link them together to create the shape. I thought that the INSIDE line will have to have a larger Radius and a centre point further along the X-Axis (Y staying constant), as then it could cut into the outside line.*

    *(I know this is not what it looks like on the picture, just my chain of thought as it will still give the same shape)

    So I defined 2nd Centre point as (X+4, Y). (Again, just estimation, thought it doesn't really matter how far apart they are).

    I then decided Radius 2 = (Chosen Font Size/20)*165 (max radius)

    So, I have my 2 Radii, and two centre points.

    This is my code so far (it works, and everything is declared/inputted above)

    for(int i=0; i<=n; i++) //output displayed to user
    Xnew = -i*(Y+R1)/n; //calculate x coordinate
    Ynew = pow((((Y+R1)*(Y+R1)) - (Xnew*Xnew)), 0.5); //calculate y coordinate


    for(int j=0; j<=n; j++)//calculation for angles and output displayed to user
    Xnew2 = -j*(Y+R2)/((n)+((0.00001)*(n==0))); //calculate x coordinate
    Ynew2 = Y*(pow(abs(1-(pow((Xnew2/X),2))),0.5));
    if(abs(Ynew2) <= R1)
    cout<<"\n("<<Xnew2<<", "<<Ynew2<<")"<<endl;

    I am having the problem drawing the crescent moon that I cannot get the two circles to have the same starting point?

    I have managed to get the results to Excel. Everything in that regard works. But when i plot the points on a graph on Excel, they do not have the same starting points. Its essentially just two half circles, one smaller than the other (Stops at the Y axis, giving the half doughnut shape).

    If this makes sense, I am trying to get two parts of circles to draw the shape as such that they have the same start and end points.

    If anyone has any suggestions on how to do this, it would be great, currently all I am getting more a 'half doughnut' shape, due to the circles not being connected.

    So. Does anyone have any hints/tips/links they can share with me on how to fix this exactly?

    Thanks again, any problems with the question, sorry will do my best to rectify if you let me know.


  2. #2
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Connecting Circles C++/Excel

    The carthesian coordinates formula for a circle is
    (x-a) + (y-b) = r
    with (x,y) being the set of points on the circumference of a circle, (a,b) being the center of the circle and r being the radius.

    You will have 2 of those formulae for each of the circle.
    circle 1 = (x1-a1) + (y1-b1) = r1
    circle 2 = (x2-a2) + (y2-b2) = r2

    the intersection point(s) of 2 circles (this will be either 2 points, 1 point or zero points) is solving the above where x1=x2 and y1=y2

    so you have 4 conditions, and need to calculate x and y where all 2 conditions are true.
    you basically start out by reformulating the circle formula's so it puts x or y as a left and everything else as a right, (x = something or y = something)
    since both x's and y's need to be identical, you then equate both to eachother and solve for the other variable.
    so for example separating out x's.
    x1 = somethingsomething1
    x2 = somethingsomething2

    somethingsomething1 = somethingsomething2

    since both y's are expected equal, you substitute both y1 and y2 by plain "y" and solve.

    that's the general approach.
    You can make things a lot easier if you can assume that both centerpoints will be on the x or y axis.
    it becomes a lot easier if you can assume either centerpoint is at (0,0).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.