how to write a function

Discussion in 'C' started by allwiyn, Aug 23, 2007.

  1. allwiyn

    allwiyn New Member

    Joined:
    Aug 23, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    How to write a function that checks if the circle passes through four given points.

    plz give me the logic or concept for making this function.
     
  2. seeguna

    seeguna New Member

    Joined:
    Jun 20, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Technical Consultant
    Location:
    Chennai
    It is better to go thru some circle clipping algorithms for better implementation
     
  3. oleber

    oleber New Member

    Joined:
    Apr 23, 2007
    Messages:
    37
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Software Developer (Perl, C/C++ and Java)
    Location:
    Hamburg, Germany
    Home Page:
    http://oleber.freehostia.com/
    Calculate the center of the circle (probably you have it :p).

    And calculate the distance of this points to the center. :cool: Mathematics
     
  4. listendinesh

    listendinesh New Member

    Joined:
    Aug 3, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    If you have radius and center cordinates then you can use the standred equation of circle.

    ((X- H)*(X -H)) + ((Y -K)*(Y - K)) = R*R


    H -> center x cordinate
    K -> center y cordinate
    R -> Radius

    X -> x cordinate of given point
    Y -> y cordinate of given point

    Make a function which take two arguments ( given point x and y cordinate) and return a bool flag ( true if circle passes through given point otherwise false).
    In function
    calculate X -H and get its sqrt
    (Given point X - Center Point X)
    calculate Y -K and get its sqrt
    add both result and compare with radius square
    if both equal the and get its sqrt

    Note :
    1 : Please take care of floating point issues
    2 : This is for one point you can extend for more points
    3 : make a struct for point , that would be a good candidate like
    Code:
    struct point
    {
    int x,
    int y
    };
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice