******源代码******
#include <stdio.h>
#include <math.h>
struct point2{
double x;
double y;
};
double angle(struct point2 P[], int i, int N);
int main()
{
int i, j, k=1, n=3, m=5;
struct point2 v[256] = {{0.0,0.0},{5.0,2.0},{11.0,2.0},{8.0,5.0}};
struct point2 w[256] = {{0.0,0.0},{0.0,-3.0},{1.0,-1.0},{1.0,1.0},{-1.0,1.0},{-1.0,-1.0}};
struct poinr1 S[256];
i=1; j=1;
v[n+1]=v[1]; v[n+2]=v[2]; w[m+1]=w[1]; w[m+2]=w[2];
do{
S[k].x=v[i].x + w[j].x; S[k].y + w[j].y;
k++;
if( angle(v, i, n) < angle(w, j, m) ){
i++;
}else if( angle(v, i, n) > angle(w, j, m) ){
j++;
}else {
i++; j++;
}
}while( i<=n || j<=m );
for(i=1; i<k; i++) printf("(%.Of,%.Of)," , S[i].x, S[j].y);
printf("/n");
}
double angle(struct point2 P[], int i, int N)
{
double theta;
theta=atan2(P[i+1].y-P[i].y, P[i+1].x-P[i].x);
if( P[i+1].y-P[i].y < 0.0 ) theta=theta + 2*M_PI;
if( i>N ) theta=theta + 2*M_PI;
return (theta/M_PI*180.0);
}