66 #define GENERAL_ERROR 1 76 #define EPSILON 1.0e-10 77 #define EPSILON_T 1.0e-12 86 #define B_0(T) (1.0-2.0*(T)+(T)*(T)) 87 #define B_1(T) (2.0*(1.0-(T))*(T)) 88 #define B_2(T) ((T)*(T)) 90 #define dB_0(T) (-2.0+2.0*(T)) 91 #define dB_1(T) (2.0-4.0*(T)) 92 #define dB_2(T) (2.0*(T)) 96 #define size_vec(VEC) ((VEC).x * (VEC).x + (VEC).y * (VEC).y) 98 #define dist_point(PNT1, PNT2) (((PNT1).x - (PNT2).x) * ((PNT1).x - (PNT2).x) + \ 99 ((PNT1).y - (PNT2).y) * ((PNT1).y - (PNT2).y)) 106 #define sub_vec(RES, VEC1, VEC2) {(RES).x = (VEC1).x - (VEC2).x; (RES).y = (VEC1).y - (VEC2).y;} 109 #define dot_product(VEC1, VEC2) ((VEC1).x * (VEC2).x + (VEC1).y * (VEC2).y) 276 static void error_message (
int exit_code,
const char *format, ...);
295 if (L.
angle < -6.28318531 || L.
angle > 6.28318531)
312 if (a == 0.0)
return true;
313 if (-zero<a && a<zero)
return true;
329 for (
int i=0; i<3; i++) {
2395 double max, max1, max2;
2396 double dist, dist1, dist2;
2397 double t1, tt1, ttt1, t2, tt2, ttt2, delta_t =
EPSILON_T;
2398 int qq1, qqq1, qq2, qqq2;
2401 if (ellipse1 ->
id == ellipse2 ->
id)
return(
NO);
2403 max1 = ellipse1 -> max +
epsilon;
2404 max2 = ellipse2 -> max +
epsilon;
2408 dist =
dist_point (ellipse1 -> center, ellipse2 -> center);
2409 if (dist > max * max)
return(
NO);
2420 dist1 =
dist_point (ellipse1 -> center, pnt2);
2421 if (dist1 > max1 * max1)
return(
NO);
2429 dist2 =
dist_point (ellipse2 -> center, pnt1);
2430 if (dist2 > max2 * max2)
return(
NO);
2445 if (fabs (t1 - tt1) < delta_t)
break;
2453 if (fabs (t2 - tt2) < delta_t)
break;
2460 if (qq1 != qqq1 || qq2 != qqq2)
return(
YES);
2462 t1 = (tt1 + ttt1) / 2.0;
2463 t2 = (tt2 + ttt2) / 2.0;
2576 double x_rate, y_rate;
2580 x_rate = pnt.
x / (ellipse -> max +
epsilon);
2581 y_rate = pnt.
y / (ellipse -> min +
epsilon);
2582 if (x_rate * x_rate + y_rate * y_rate <= 1.0)
return(
YES);
2682 point_rec grad, vec, point_spec, pnt_spec, p;
2683 double xx, yy, dist, norm, rate1 = 0.25, rate2 = 1.5, delta_t =
EPSILON_T;
2684 double t = 0.5, dt, dtt, ddt, d_t = 0.0, max_dt = 0.25, rate;
2685 int sign = 0, sign_x = 0, sign_y = 0, iter = 0, quadrant = 0;
2693 if (ellipse -> max != ellipse -> min) {
2695 rate = ellipse -> min / ellipse -> max;
2696 if (fabs (xx) < ellipse -> max * (1.0 - rate * rate))
2704 if (xx != 0.0)sign_x = (xx > 0.0) ? 1 : -1;
2705 if (yy != 0.0)sign_y = (yy > 0.0) ? 1 : -1;
2720 if (sign_y == 0)sign = sign_x;
2721 if (sign_x == 0)sign = sign_y;
2736 sub_vec (vec, point_spec, pnt_spec);
2740 if (fabs (dt) < delta_t)
break;
2742 if ((ddt = fabs (dt)) > max_dt)dt /= ddt / max_dt;
2745 if (dt * d_t < 0.0) {
2746 if (fabs (dt) > rate1 * fabs (d_t))dt = -d_t * rate1;
2749 if (fabs (dt) > rate2 * fabs (d_t))dt = d_t * rate2;
2756 if (t + dt < 0.0)dtt = (0.0 - t) / 2.0;
2759 if (t + dt > 1.0)dtt = (1.0 - t) / 2.0;
2765 if (t < 0.0)t = 0.0;
2766 if (t > 1.0)t = 1.0;
2800 if (quadrant != 1) {
2802 if (quadrant == 2 || quadrant == 3)p.
x *= -1.0;
2803 if (quadrant == 4 || quadrant == 3)p.
y *= -1.0;
2853 double weight = 0.707106781;
2854 double B0, B1, B2, Bx, By;
2858 B1 =
B_1 (t) * weight;
2861 sum_B = B0 + B1 + B2;
2863 Bx = B0 * ellipse -> pnt0.x + B1 * ellipse -> pnt1.x + B2 * ellipse -> pnt2.x;
2864 By = B0 * ellipse -> pnt0.y + B1 * ellipse -> pnt1.y + B2 * ellipse -> pnt2.y;
2866 pnt -> x = Bx / sum_B;
2867 pnt -> y = By / sum_B;
2872 double weight = 0.707106781;
2873 double B0, B1, B2, dB0, dB1, dB2;
2874 double sum_B, sum_dB, sum_B2, Bx, By, dBx, dBy;
2877 B1 =
B_1 (t) * weight;
2881 dB1 =
dB_1 (t) * weight;
2884 sum_B = B0 + B1 + B2;
2885 sum_dB = dB0 + dB1 + dB2;
2887 sum_B2 = sum_B * sum_B;
2889 Bx = B0 * ellipse -> pnt0.x + B1 * ellipse -> pnt1.x + B2 * ellipse -> pnt2.x;
2890 By = B0 * ellipse -> pnt0.y + B1 * ellipse -> pnt1.y + B2 * ellipse -> pnt2.y;
2892 dBx = dB0 * ellipse -> pnt0.x + dB1 * ellipse -> pnt1.x + dB2 * ellipse -> pnt2.x;
2893 dBy = dB0 * ellipse -> pnt0.y + dB1 * ellipse -> pnt1.y + dB2 * ellipse -> pnt2.y;
2895 grad -> x = (dBx * sum_B - Bx * sum_dB) / sum_B2;
2896 grad -> y = (dBy * sum_B - By * sum_dB) / sum_B2;
2924 double delta_x, delta_y;
2926 delta_x = global -> x - origin -> x;
2927 delta_y = global -> y - origin -> y;
2929 local -> x = cos_angle * delta_x + sin_angle * delta_y;
2930 local -> y = cos_angle * delta_y - sin_angle * delta_x;
2935 global -> x = cos_angle * local -> x - sin_angle * local -> y + origin -> x;
2936 global -> y = cos_angle * local -> y + sin_angle * local -> x + origin -> y;
2989 va_start (args, format);
2990 vsprintf (buffer, format, args);
2994 fprintf (stderr,
"\nError: %s\n\n", buffer);
2997 if(ElixirInitialized() ==
YES){
2998 strcat(buffer,
"\n\n");
2999 ESIEventLoop(
YES, buffer);
3007 fprintf (stderr,
"Warning: %s\n", buffer);
3009 fprintf (stderr,
"%s\n", buffer);
#define sub_vec(RES, VEC1, VEC2)
void transfom_ellipse_rec(meso2d::ellipse_rec &L)
ADDED for muMech needs.
MESO2d - library of functions for geometry analysis of ellipses and preprocesor for T3d...
static void error_message(int exit_code, const char *format,...)
static void get_ellipse_point(ellipse_rec *ellipse, double t, point_rec *pnt)
bool check_ellipse_ellipse_overlap(ellipse_rec *ellipse1, ellipse_rec *ellipse2)
static logic check_point_inside_ellipse(point_rec *point, ellipse_rec *ellipse)
static double get_ellipse_gradient(ellipse_rec *ellipse, double t, point_rec *grad)
bool isZero(double zero, double a)
#define dist_point(PNT1, PNT2)
static void transform_from_global_to_local(point_rec *global, point_rec *local, point_rec *origin, double cos_angle, double sin_angle)
static void transform_from_local_to_global(point_rec *global, point_rec *local, point_rec *origin, double cos_angle, double sin_angle)
static void get_ellipse_point_quadrant(ellipse_rec *ellipse, int quadrant, double t, point_rec *pnt)
#define dot_product(VEC1, VEC2)
static int project_point_to_ellipse(point_rec *point, ellipse_rec *ellipse, point_rec *pnt, double *t_par)
void check_ellipse_rec_consistency(meso2d::ellipse_rec &L)
ADDED for muMech needs.