43 for (i = 0; i < arraylength; i++)
45 for (j = i + 1; j < arraylength; j++)
48 if (inout[j].x > inout[i].x)
69 for (i = 0; i < arraylength; i++)
71 for (j = i + 1; j < arraylength; j++)
73 if (inout[j].y > inout[i].y)
90 return (p2.x - p1.x) * (p3.y - p2.y) - (p3.x - p2.x) * (p2.y - p1.y) >= 0;
99 return (p2.x - p1.x) * (p3.y - p2.y) - (p3.x - p2.x) * (p2.y - p1.y) <= 0;
108 return (
Point.y - linePoint1.y) * (linePoint2.x - linePoint1.x) - (
Point.x - linePoint1.x) * (linePoint2.y - linePoint1.y) < 0;
136 int left_points_counter, right_points_counter;
138 for (
int i = 0; i < num_all_points; i++)
143 SortByY(temp1, num_all_points);
145 hull_left[0] = temp1[num_all_points - 1];
146 hull_left[1] = temp1[0];
147 hull_right[0] = temp1[num_all_points - 1];
148 hull_right[1] = temp1[0];
149 float divided_x_dif = (temp1[0].x - temp1[num_all_points - 1].x) / (temp1[0].y - temp1[num_all_points - 1].y);
155 left_points_counter = 0;
156 right_points_counter = 0;
157 for (
int i = 1; i < num_all_points - 1; i++)
159 if (temp1[i].x < temp1[0].x + (temp1[i].y - temp1[0].y)*divided_x_dif)
161 temp2[left_points_counter] = temp1[i];
162 left_points_counter++;
166 temp2[num_all_points - 1 - right_points_counter] = temp1[i];
167 right_points_counter++;
171 temp2[left_points_counter] = temp1[num_all_points - 1];
172 left_points_counter++;
173 temp2[num_all_points - 1 - right_points_counter] = temp1[num_all_points - 1];
174 right_points_counter++;
179 hull_left[2] = temp2[0];
180 for (
int i = 1; i < left_points_counter; i++)
182 while (
RightTurn(hull_left[hull_ind_l - 1], hull_left[hull_ind_l], temp2[i]))
187 hull_left[hull_ind_l] = temp2[i];
189 *num_hull_points_left = hull_ind_l + 1;
194 hull_right[2] = temp2[num_all_points - 1];
195 for (
int i = 2; i <= right_points_counter; i++)
197 while (
LeftTurn(hull_right[hull_ind_r - 1], hull_right[hull_ind_r], temp2[num_all_points - i]))
202 hull_right[hull_ind_r] = temp2[num_all_points - i];
204 *num_hull_points_right = hull_ind_r + 1;
215 CalcConvexHull(in, num_all_points, hull_left, num_hull_points_left, hull_right, num_hull_points_right, temp1, temp2);
234 while (ind_l < pol->nCornersLeft - 1 && ind_r < pol->nCornersRight - 1)
239 pol->
hull[ind_h].z = 1;
245 pol->
hull[ind_h].z = 2;
251 while (ind_l < pol->nCornersLeft - 1)
254 pol->
hull[ind_h].z = 1;
258 while (ind_r < pol->nCornersRight - 1)
261 pol->
hull[ind_h].z = 2;
338 int left_points_counter, right_points_counter;
342 pol->
hullLeft[0] = hullpoints[nPoints - 1];
344 pol->
hullRight[0] = hullpoints[nPoints - 1];
346 float divided_x_dif = (hullpoints[0].x - hullpoints[nPoints - 1].x) / (hullpoints[0].y - hullpoints[nPoints - 1].y);
348 pol->
hull[0].x = hullpoints[0].x;
349 pol->
hull[0].y = hullpoints[0].y;
351 pol->
hull[nPoints - 1].x = hullpoints[nPoints - 1].x;
352 pol->
hull[nPoints - 1].y = hullpoints[nPoints - 1].y;
353 pol->
hull[nPoints - 1].z = 3;
355 left_points_counter = 2;
356 right_points_counter = 2;
357 for (
int i = 1; i < nPoints - 1; i++)
359 pol->
hull[i].x = hullpoints[i].x;
360 pol->
hull[i].y = hullpoints[i].y;
361 if (hullpoints[i].x < hullpoints[0].x + (hullpoints[i].y - hullpoints[0].y)*divided_x_dif)
363 pol->
hullLeft[left_points_counter] = hullpoints[i];
365 left_points_counter++;
369 pol->
hullRight[right_points_counter] = hullpoints[i];
371 right_points_counter++;
375 pol->
hullLeft[left_points_counter] = hullpoints[nPoints - 1];
376 pol->
hullRight[right_points_counter] = hullpoints[nPoints - 1];
450 if (boolTable[j] ==
true)
452 pointAccu[pointcount] = p1->
hull[j];
474 if (boolTable[j] ==
true)
476 pointAccu[pointcount] = p2->
hull[j];
495 float x1, y1, x2, y2, x3, y3, x4, y4, c1, c2, denominator;
510 denominator = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
511 c1 = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / denominator;
512 c2 = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / denominator;
513 if (0 <= c1 && 1 >= c1 && 0 <= c2 && 1 >= c2)
515 pointAccu[pointcount].x = x1 + c1 * (x2 - x1);
516 pointAccu[pointcount].y = y1 + c1 * (y2 - y1);