Like Tree1Likes
  • 1 Post By Salem

Point to lie on a circle. Help!

This is a discussion on Point to lie on a circle. Help! within the C++ Programming forums, part of the General Programming Boards category; Please, would you help me with this program: Code: #include <iostream> #include <cmath> using namespace std; void main() { cout ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    8

    Point to lie on a circle. Help!

    Please, would you help me with this program:

    Code:
     #include <iostream>
     #include <cmath>
     using namespace std;
    
     void main()
     {
     cout << "x = ";
     double x;
     cin >> x;
    
     cout << "y = ";
     double y;
     cin >> y;
    
     bool c1 = ((((x + 1)*(x + 1) + (y - 1)*(y - 1)) <= 1) && 
     (y <= (1/3*x + 1)) && 
     (y >= (x + 1)) &&
     (y >= 0));
    
     if (c1)
     cout << "true" << endl;
     else
     cout << "false" << endl;
    
     }
    http://img38.imageshack.us/img38/8481/cird.png Uploaded with ImageShack.us

    The point don`t have to lie in (-2, 0.5), (-2, 1) and (0,1). :S

  2. #2
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Sure:

    1. It's int main(). Read why void main() is wrong
    2. Learn how to indent your code.
    3. Learn how to ask questions.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,530
    On a circle?
    In a circle?
    In the shaded area?

    We need more than some random uncommented code, and an unexplained picture.
    iMalc likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Shouldn't you have more than just one set of numbers? Like D is the diameter of the circle, and X,Y is the coordinate of the center of the circle, and pX,pY is the coordinates of the point you want to check? You have X and Y, but what are you comparing X and Y to? You can't find out if something is relative to a coordinate, if you only have one of the two pairs of coordinates.

    "Is this point on a line?"
    "Maybe."


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Quzah is right. You cannot solve this problem without knowing the center of the circle and the radius or diameter of the circle. Since a circle is the set of all points equidistant from a center point the check to see if px,py lies on the circle is simple if you know those two pieces of information about the circle.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    From the diagram, we know the centre of the circle. I think what we don't know is what the original poster is actually asking.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Mar 2011
    Posts
    8
    Thank you!

  8. #8
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    For what? You have not explained what you want.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I still don't know what that shaded area is supposed to be. The area of triangle 0/-1,-1/0,-3/0 that happens to fall in the circle? That doesn't really do anything for us as far as finding "a point to lie on a circle".


    Quzah.
    Last edited by quzah; 08-08-2011 at 01:37 AM.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-27-2011, 04:34 AM
  2. fixed point / floating point
    By confuted in forum Game Programming
    Replies: 4
    Last Post: 08-13-2002, 01:25 PM
  3. point lies in circle?
    By cozman in forum Game Programming
    Replies: 3
    Last Post: 12-20-2001, 03:39 PM
  4. Floating point faster than fixed-point
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-08-2001, 10:34 PM
  5. Finding a point within a circle
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 09-23-2001, 08:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21