gdouble triangle_circumcircle_radius( Point2 *p1, Point2 *p2, Point2 *p3 ) { return triangle_circumcircle_radius_edge_length( point2_distance(p1,p2), point2_distance(p2,p3), point2_distance(p3,p1) ); }
gdouble triangle_area( const Point2 *p1, const Point2 *p2, const Point2 *p3 ) { gdouble l1 = point2_distance( p1, p2 ); gdouble l2 = point2_distance( p2, p3 ); gdouble l3 = point2_distance( p3, p1 ); gdouble s = 0.5*( l1 + l2 + l3 ); return sqrt( s*( s-l1 )*( s-l2 )*( s-l3 ) ); }
void element_edge_lengths( const Element *element, gdouble *length1, gdouble *length2, gdouble *length3 ) { g_return_if_fail( element != NULL ); g_return_if_fail( length1 != NULL ); g_return_if_fail( length2 != NULL ); g_return_if_fail( length3 != NULL ); HalfEdge *he = element->adjacent_halfedge; Point2 *p1 = NODE_POSITION(he->origin); Point2 *p2 = NODE_POSITION(he->next->origin); Point2 *p3 = NODE_POSITION(he->next->next->origin); *length1 = point2_distance( p1, p2 ); *length2 = point2_distance( p2, p3 ); *length3 = point2_distance( p3, p1 ); }
gdouble element_fem_quality( const Element * el ) { g_return_val_if_fail( el != NULL, G_MAXDOUBLE ); HalfEdge *he = el->adjacent_halfedge; Point2 *p1 = NODE_POSITION(he->origin); Point2 *p2 = NODE_POSITION(he->next->origin); Point2 *p3 = NODE_POSITION(he->previous->origin); gdouble a, b, c; a = point2_distance( p1, p2 ); b = point2_distance( p2, p3 ); c = point2_distance( p3, p1 ); // ratio of the longest edge length and the radius of inscribed circle gdouble h_max = MAX( a, MAX( b, c ) ); gdouble s = ( a + b + c )/2.0; return 2.0 * SQRT3 * sqrt((s-a)*(s-b)*(s-c)/s) / h_max; }
void triangle_angles( const Point2 *p1, const Point2 *p2, const Point2 *p3, gdouble *angle1, gdouble *angle2, gdouble *angle3 ) { g_return_if_fail( p1 != NULL ); g_return_if_fail( p2 != NULL ); g_return_if_fail( p3 != NULL ); g_return_if_fail( angle1 != NULL ); g_return_if_fail( angle2 != NULL ); g_return_if_fail( angle3 != NULL ); gdouble a, b, c; a = point2_distance( p2, p3 ); b = point2_distance( p1, p3 ); c = point2_distance( p1, p2 ); gdouble aa = a*a; gdouble bb = b*b; gdouble cc = c*c; *angle1 = acos( (bb+cc-aa)/(2.0*b*c) ); *angle2 = acos( (aa+cc-bb)/(2.0*a*c) ); *angle3 = acos( (aa+bb-cc)/(2.0*a*b) ); }
int test_point2( int argc, char *argv[] ) { Point2 p1, p2, p3, p; point2_set( &p1, 1.23456789, 4.678692 ); g_return_val_if_fail( p1.x == 1.23456789, 1 ); g_return_val_if_fail( p1.y == 4.678692, 1 ); point2_set( &p1, -1.0, 0.0 ); point2_set( &p2, 0.0, 1.0 ); g_return_val_if_fail( fabs( point2_distance( &p1, &p2 ) - sqrt(2.0) ) < SMALL_NUMBER, 1 ); point2_set( &p1, 0.0, 1.0 ); point2_set( &p2, -1.0, 0.0 ); point2_set( &p3, 1.0, 0.0 ); point2_set( &p, 0.0, 0.5 ); g_return_val_if_fail( point2_is_in_triangle( &p, &p1, &p2, &p3 ), 1 ); point2_set( &p, 0.0, 0.0 ); g_return_val_if_fail( ! point2_is_in_triangle( &p, &p1, &p2, &p3 ), 1 ); point2_set( &p, 0.5, 0.5 ); g_return_val_if_fail( ! point2_is_in_triangle( &p, &p1, &p2, &p3 ), 1 ); point2_set( &p, 0.5, 0.5 ); g_return_val_if_fail( ! point2_is_in_triangle( &p, &p1, &p2, &p3 ), 1 ); point2_set( &p, 1.0, 0.0 ); g_return_val_if_fail( ! point2_is_in_triangle( &p, &p1, &p2, &p3 ), 1 ); point2_set( &p1, -1.0, -1.0 ); point2_set( &p2, 1.0, 1.0 ); p = point2_interpolate( &p1, &p2, 0.0 ); g_return_val_if_fail( p.x == p1.x, 1 ); g_return_val_if_fail( p.y == p1.y, 1 ); p = point2_interpolate( &p1, &p2, 1.0 ); g_return_val_if_fail( p.x == p2.x, 1 ); g_return_val_if_fail( p.y == p2.y, 1 ); p = point2_interpolate( &p1, &p2, 0.5 ); g_return_val_if_fail( fabs( p.x ) < DBL_EPSILON, 1 ); g_return_val_if_fail( fabs( p.y ) < DBL_EPSILON, 1 ); return 0; }
polygon2_t* polygon2_star(point2_t* x0, point2_t* points, int num_points) { // Make sure x0 is not one of the points. for (int i = 0; i < num_points; ++i) { if (point2_distance(x0, &points[i]) < 1e-14) polymec_error("polygon2_star: Point %d coincides with x0.", i); } // Sort the points by angles. star_angle_t angles[num_points]; for (int i = 0; i < num_points; ++i) { angles[i].angle = atan2(points[i].y - x0->y, points[i].x - x0->x); angles[i].index = i; } qsort(angles, (size_t)num_points, sizeof(star_angle_t), star_angle_cmp); // Create a polygon from the new ordering. int ordering[num_points]; for (int i = 0; i < num_points; ++i) ordering[i] = angles[i].index; return polygon2_new_with_ordering(points, ordering, num_points); }
gdouble edge_length( const Edge *edge ) { Point2 *p1 = NODE_POSITION( edge->he[0].origin ); Point2 *p2 = NODE_POSITION( edge->he[1].origin ); return point2_distance( p1, p2 ); }