Thread: Finding intersection points of two ellipses (Using C program)

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    6

    Post Finding intersection points of two ellipses (Using C program)

    Today i am going find out solution of two ellipses intersection points using C programming but i am not find out know idea, I solved using geometry equation substitute method but i am not unable to do same thing in C programming please help me .I am talking example as following two ellipses
    (x^2)/4+y^2=1 ,
    ((x-2)^2)/4+y^2=1
    please give me any suggestion so i will proceed head.
    Last edited by tpvamsi; 10-16-2014 at 01:02 AM. Reason: format

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    What have you tried to do in C?
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by grumpy View Post
    What have you tried to do in C?
    Actually i want find out using C program two ellipse intersection or not for that how to start please help.

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    What grumpy was asking you to do is provide an effort.
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by Click_here View Post
    What grumpy was asking you to do is provide an effort.
    I want intersection between ellipse or not
    Attached Images Attached Images Finding intersection points of two ellipses (Using C program)-hmdyc-png 

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    We already know what you want.

    Read the site's homework policy, here. This is not a free code factory. If you want help, demonstrate a genuine effort to solve your problem on your own - with code. Then people might consider helping you with specific problems you have encountered.

    But, then again, from your behaviour, what you seek is someone to write the code for you, rather than doing it yourself. That won't happen.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Registered User
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by grumpy View Post
    We already know what you want.

    Read the site's homework policy, here. This is not a free code factory. If you want help, demonstrate a genuine effort to solve your problem on your own - with code. Then people might consider helping you with specific problems you have encountered.

    But, then again, from your behaviour, what you seek is someone to write the code for you, rather than doing it yourself. That won't happen.
    Today i tried following is my code :

    Code:
    #include<stdio.h>
    #include<math.h>
    
    
    int intersection(float,float,float,float,float,float,float,float);
    int main()
    {
        int x1,y1,a1,b1,x2,y2,a2,b2;
        int ret;
    //    ret=intersection(x1,y1,a1,b1,x2,y2,a2,b2);
        ret=intersection(2,2,2,1,7,2,2,1);
        if(ret==1)
            printf("Two ellipses are intersect\n");
        else
            printf("Two ellipses are not intersect\n");
    
    
    
    
        return 0;
        
    }
    
    
    
    
    
    
    int intersection(float x1,float y1,float a1,float b1,float x2,float y2,float a2,float b2)
    {
        float x,y;
        float z;
        x=(1/(a2*b1-a1*b2)*(a2*b1-a1*b2))*(-sqrt(-(a1*a1*a2*a2)*(y1-y2)*(y1-y2)*(a2*b1-a1*b2)*(a2*b1-a1*b2)));
        y=(1/(a2*b1-a1*b2)*(a2*b1-a1*b2))*((a1*a1*b2*b2*x2)-(a1*a2*b1*b2*x1)-(a1*a2*b1*b2*x2)+(a2*a2*b1*b1*x1));
        z=(1/(a2*b1-a1*b2)*(a2*b1-a1*b2));
        printf("result of intersection is %f   and %f   and  %f",x,y,z);
    
    
        return 1;
    }
    after compiling it giving following output:
    result of intersection is -nan and -nan and -nanTwo ellipses are intersect

    I am getting -nan as output why i am not understand
    please help me
    Last edited by tpvamsi; 10-28-2014 at 12:41 AM.

  8. #8
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Check to see if you are dividing by 0.
    Fact - Beethoven wrote his first symphony in C

  9. #9
    Registered User
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by Click_here View Post
    Check to see if you are dividing by 0.
    Thanks

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    You don't really want an explanation of why you are getting NaNs, so I'm not even going to bother with that.

    To fix the problem, try breaking down your calculations into smaller parts, and check each of the parts before combining them.

    Before computing a/b, check that b (however you calculated it) is not zero. Before computing sqrt(something), check that the something is not negative.

    Dividing by zero doesn't produce NaNs. However, multiplying the result of that (an infinity) by zero does produce NaNs.




    Note: not all compilers support IEEE floating point format. If your code is built with such a compiler, it will not produce NaNs - instead you'd be asking questions about program crashes (e.g. reporting a division by zero, or some such).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  11. #11
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Your function intersect currently returns 1 in all cases, and your main program interprets this to mean that they intersect in all cases. Maybe you forgot a step in your function? E.g. a conditional to say whether the ellipses intersect

  12. #12
    Registered User
    Join Date
    Oct 2014
    Posts
    6
    Quote Originally Posted by grumpy View Post
    You don't really want an explanation of why you are getting NaNs, so I'm not even going to bother with that.

    To fix the problem, try breaking down your calculations into smaller parts, and check each of the parts before combining them.

    Before computing a/b, check that b (however you calculated it) is not zero. Before computing sqrt(something), check that the something is not negative.

    Dividing by zero doesn't produce NaNs. However, multiplying the result of that (an infinity) by zero does produce NaNs.




    Note: not all compilers support IEEE floating point format. If your code is built with such a compiler, it will not produce NaNs - instead you'd be asking questions about program crashes (e.g. reporting a division by zero, or some such).
    Thanks to all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Ellipses and Efficiency?
    By HelpfulPerson in forum C Programming
    Replies: 3
    Last Post: 11-06-2013, 01:59 AM
  2. C++ Plot Simple Points / Graph, X & Y array points
    By Khadafi in forum C++ Programming
    Replies: 9
    Last Post: 11-11-2011, 03:47 AM
  3. Help with finding the intersection of 2 strings
    By hay_man in forum C++ Programming
    Replies: 5
    Last Post: 09-30-2006, 06:30 PM
  4. Ellipses (that stretch) in DirectDraw
    By Cheeze-It in forum Game Programming
    Replies: 2
    Last Post: 02-26-2006, 04:11 PM

Tags for this Thread