Point Circle Relationship---3

Source: Internet
Author: User

Enter the code:

/**copyright (c) 2015, College of Computer and Control engineering, Yantai University *all rights reserved.* file name: sum123.cpp* Author: Lin Haiyun * Completion date: June 12, 2015 * version number: v2.0**            Problem Description: A line connected to the center of the circle: given a point p, which is connected to the center of the line, and the circle has two intersections. Based on the point and Circle (circle) classes defined above, a scheme is designed to output the coordinates of these two points. * Program Input: NO * program output: Output the intersection of two circles as required */#include <iostream> #include <cmath>using namespace Std;class circle;class Point {public:point (double a=0,double b=0): X (a), Y (b) {} Friend Ostream & operator<< (ostream &,const Point &    amp;);  friend void Crossover_point (Point &p,circle &c, point &p1,point &p2); The friend function protected:double X,y;};o of intersection Stream & operator<< (ostream &output,const point &p) {output<< "[" <<p.x<< "," <    <p.y<< "]"; return output;} Class Circle:public point{public:circle (double a=0,double b=0,double r=0):P oint (A, B), radius (r) {} friend Ostream &    amp;operator<< (ostream &,const Circle &); friend void Crossover_point (Point &p,circle &c, point &p1,point &amP;P2); The friend function protected:double radius;};/of intersection /overloaded operator "<<" to output circle information in a prescribed form ostream &operator<< (ostream &output,const circle &c) {output<    < "center=[" <<c.x<< "," <<c.y<< "], r=" <<c.radius; return output;} void Crossover_point (Point &p, Circle &c, point &p1,point &p2) {p1.x = (c.x + sqrt (c.radius*c.radius/(    1+ ((C.Y-P.Y)/(c.x-p.x)) * ((C.Y-P.Y)/(c.x-p.x))));    p2.x = (c.x-sqrt (c.radius*c.radius/(1+ ((C.Y-P.Y)/(c.x-p.x)) * ((C.Y-P.Y)/(c.x-p.x))));    P1.y = (p.y + (p1.x-p.x) * (C.Y-P.Y)/(c.x-p.x)); P2.y = (p.y + (p2.x-p.x) * (C.Y-P.Y)/(c.x-p.x));}    int main () {Circle C1 (3,2,4);    Point P1 (P2,P3);    Crossover_point (P1,C1, p2, p3);    cout<< "point p1:" <<p1<<endl;    cout<< "with Circle C1:" <<c1<<endl;    The center of the cout<< "is connected with the circle at two o'clock, respectively:" <<endl;    cout<< "Intersection 1:" <<p2<<endl;    cout<< "Intersection 2:" <<p3<<endl; return 0;}

Operation Result:


Point Circle Relationship---3

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.