source: CIVL/examples/compare/provesa/head.c

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 2.0 KB
Line 
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
25double 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
Note: See TracBrowser for help on using the repository browser.