Question: Find a point in the quadrilateral to the distance and minimum of all vertices. Analysis: Calculation of ry and Fermat points. In a triangle, the distance to all vertices and the smallest vertex are called the horse points. For a triangle: if it is a non-Blunt triangle, it is the center of gravity; otherwise it is the blunt vertex. For a quadrilateral: If a convex quadrilateral is used, it is the diagonal intersection. The sub-part is one of the vertices. For polygon: there is no standard formula. You can use the greedy method to approach it immediately. Note: The quadrilateral given in the question may be two triangles on the top, for example, the sample. [Cpp] # include <iostream> # include <cstdlib> # include <cstdio> # include <cmath> using namespace std; typedef struct pnode {double x, y; pnode (double a, double B) {x = a; y = B;} pnode () {};} point; point P [5]; typedef struct lnode {double x, y, dx, dy; lnode (point a, point B) {x =. x; y =. y; dx = B. x-a.x; dy = B. y-a.y;} lnode () {};} line; double dist (point a, point B) {return sqrt (. x-b.x) * (. x -B. x) + (. y-b.y) * (. y-b.y);} double dist (point p, int N) {double sum = 0.0; for (int I = 0; I <N; ++ I) sum + = dist (p, P [I]); return sum;} double p_to_l (point a, line l) {return l. dx * (. y-l.y)-l. dy * (. x-l.x);} point l_cross_s (line l, point a, point B) {line m = line (a, B); if (m. dx * l. dy = m. dy * l. dx) return a; else {double a1 =-l. dy, b1 = l. dx, c1 = l. dx * l. y-l.dy * l. x; double A2 =-m. dy, b2 = m. dx, c2 = m. dx * m. y-m.dy * m. x; double x = (c1 * b2-c2 * b1)/(a1 * b2-a2 * b1); double y = (c1 * a2-c2 * a1)/(b1 * a2-b2 * a1 ); return point (x, y) ;}} int main () {while (scanf ("% lf", & P [0]. x, & P [0]. y )! = EOF) {if (P [0]. x =-1) break; for (int I = 1; I <4; ++ I) scanf ("% lf", & P [I]. x, & P [I]. y); // judge the vertex double temp, min = dist (P [0], 4); for (int I = 1; I <4; ++ I) {temp = dist (P [I], 4); if (min> temp) min = temp;} // determines the intersection point p4, p3, p2, p1 = P [0]; int U [4]; for (int I = 1; I <4; ++ I) {for (int j = 1; j <4; + + j) U [j] = 0; U [I] = 1; p2 = P [I]; for (int j = 1; j <4; ++ J) if (! U [j]) {U [j] = 1; p3 = P [j]; break;} for (int j = 1; j <4; ++ j) if (! U [j]) {U [j] = 1; p4 = P [j]; break;} www.2cto.com line l1 = line (p1, p2 ); line l2 = line (p3, p4); if (p_to_l (p1, l2) * p_to_l (p2, l2) <= 0) if (p_to_l (p3, l1) * p_to_l (p4, l1) <= 0) {point q = l_cross_s (line (p1, p2), p3, p4); temp = dist (q, 4 ); if (min> temp) min = temp;} printf ("%. 4lf \ n ", min);} return 0 ;}