| 1 | #define epsilon 1.00000e-14
|
|---|
| 2 |
|
|---|
| 3 | /*****************************************************************************/
|
|---|
| 4 | /* This set of functions reference triangular elements to an equilateral */
|
|---|
| 5 | /* triangle. The input are the coordinates in the following order: */
|
|---|
| 6 | /* [x1 x2 x3 y1 y2 y3] */
|
|---|
| 7 | /* A zero return value indicates success, while a nonzero value indicates */
|
|---|
| 8 | /* failure. */
|
|---|
| 9 | /*****************************************************************************/
|
|---|
| 10 | /* Not all compilers substitute out constants (especially the square root). */
|
|---|
| 11 | /* Therefore, they are substituted out manually. The values below were */
|
|---|
| 12 | /* calculated on a solaris machine using long doubles. I believe they are */
|
|---|
| 13 | /* accurate. */
|
|---|
| 14 | /*****************************************************************************/
|
|---|
| 15 |
|
|---|
| 16 | #define sqrt3 .577350269189625797959429519858 /*1.0/sqrt(3.0) */
|
|---|
| 17 | /*#define tsqrt3 1.15470053837925159591885903972 2.0/sqrt(3.0) */
|
|---|
| 18 | #define a .500000000000000000000000000000 /* 1.0/2.0 */
|
|---|
| 19 | #define b -1.00000000000000000000000000000 /* -1.0/1.0 */
|
|---|
| 20 | #define bm1 -2.00000000000000000000000000000 /* -2.0/1.0 */
|
|---|
| 21 |
|
|---|
| 22 | double tsqrt3;// = 2.0/sqrt3;
|
|---|
| 23 | //double tsqrt3 = 2.0/sqrt3;
|
|---|
| 24 |
|
|---|
| 25 | double o_fcn(double *obj, /* const */ double x[6])
|
|---|
| 26 | {
|
|---|
| 27 | /* static */ double matr[4], f;
|
|---|
| 28 | /* static */ double g;
|
|---|
| 29 | double retval;
|
|---|
| 30 |
|
|---|
| 31 | retval = 0.0;
|
|---|
| 32 |
|
|---|
| 33 | /* Calculate M = A*inv(W). */
|
|---|
| 34 | matr[0] = x[1] - x[0];
|
|---|
| 35 | matr[1] = (2.0*x[2] - x[1] - x[0])*sqrt3;
|
|---|
| 36 |
|
|---|
| 37 | matr[2] = x[4] - x[3];
|
|---|
| 38 | matr[3] = (2.0*x[5] - x[4] - x[3])*sqrt3;
|
|---|
| 39 |
|
|---|
| 40 | /* Calculate det(M). */
|
|---|
| 41 | g = matr[0]*matr[3] - matr[1]*matr[2];
|
|---|
| 42 | if (g <= epsilon) { *obj = g; retval = 1.0; }
|
|---|
| 43 | else {
|
|---|
| 44 | /* Calculate norm(M). */
|
|---|
| 45 | f = matr[0]*matr[0] + matr[1]*matr[1] +
|
|---|
| 46 | matr[2]*matr[2] + matr[3]*matr[3];
|
|---|
| 47 |
|
|---|
| 48 | /* Calculate objective function. */
|
|---|
| 49 | (*obj) = a * f / g;
|
|---|
| 50 | }
|
|---|
| 51 | return retval;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|