Exemple #1
0
linked_list* get_polygon_points(point* points, uint8_t length)
{
    uint8_t i, j, found;
    point* intersection_point, *tmp_point;
    linked_list* processed_points = new_linked_list();

    for(i = 0; i < length; i++) {
        found = 0;
        for(j = i + 2; j < length - 1; j++) {
            intersection_point = get_intersection_point(
                points[i], points[i + 1], points[j], points[j + 1]);
            if(intersection_point != 0) {
                tmp_point = (point*)os_malloc(sizeof(point));
                tmp_point->x = points[i].x;
                tmp_point->y = points[i].y;
                processed_points->add(processed_points, (void*)tmp_point);

                // the intersection point
                processed_points->add(processed_points, (void*)intersection_point);

                tmp_point = (point*)os_malloc(sizeof(point));
                tmp_point->x = points[j + 1].x;
                tmp_point->y = points[j + 1].y;
                processed_points->add(processed_points, (void*)tmp_point);
                found = 1;
                break;
            }
        }

        if(found == 0) {
            tmp_point = (point*)os_malloc(sizeof(point));
            tmp_point->x = points[i].x;
            tmp_point->y = points[i].y;
            processed_points->add(processed_points, (void*)tmp_point);
        } else {
            i = i + 3;
        }
    }

    return processed_points;
}
Exemple #2
0
/// 부등각 r/theta 데이터를 등각 r/theta data 로 변환 (아직 제대로 검증은 안해봤는데, excel 로 확인해 보니 그렇저렇 비슷한 형상이 나온다)
///
/// 그리고....이 함수 무쟈게 비 효율적으로 만들었다. 
/// find_neighbor_index() 를 record_count 만큼 호출하는 방식은 개선이 필요하다 
///
/// \param r (in) 부등각 radius
/// \param a (in) 부등각 angle (radian)
/// \param record_count (in) 데이터 갯수  
/// \param target_count (in) 등각 데이터 갯수 
/// \param equi_r (out) 등각 radius
/// \param equi_a (out) 등각 angle
static void make_equiangular_data(float *r, float *a, int record_count, int target_count, float *equi_r, float * equi_a)
{
	float temp_a = 2 * CONST_PI / (target_count);
	int i;
	int start, end;
	float equi_x, equi_y;

	find_neighbor_index(r, a, record_count, 0.0, &start, &end);

	for ( i = 0 ; i < target_count; i++ ) {
		equi_a[i] = temp_a * i;
		find_neighbor_index(NULL, NULL, record_count, equi_a[i], &start, &end);
		if ( start == end ) {
			equi_r[i] = r[i];
		} else {
			get_intersection_point(equi_a[i], r[start] * cos(a[start]), r[start] * sin(a[start]), r[end] * cos( a[end] ), r[end] * sin( a[end] ), &equi_x, &equi_y);

			equi_r[i] = sqrt( equi_x * equi_x + equi_y * equi_y );
		}
	}
}
Exemple #3
0
void
build_bdy_tr_mesh(const vector<Point>& outP, const vector<Point>& inP, 
                  const vector<int>& out_id, const vector<int>& in_id, 
                  const vector<double>& out_val, const vector<double>& in_val, 
                  TrMesh& trmesh)
{
   static int newp_cnt = 0;
   if( (int)inP.size() == 1 )
   {
      vector<int> vid; vid.resize(3,-1);
      // the three vertices are the intersection points between inP[0] and outP[0,1,2].
      for(int i = 0; i < 3; i ++)
      {
         int id = -1;
         if( find_id( in_id[0], out_id[i], id ) )
            vid[i] = id;
         else
         {
            Point p = get_intersection_point( in_val, out_val, inP, outP, 0, i );
            // add this point to the mesh.
            TrVertex* new_v = new TrVertex(p);
            trmesh.v_list.push_back(new_v);
            // record the id of this new point associated with in_id[0] and out_id[i].
            id = newp_cnt;
            set_id( in_id[0], out_id[i], id);
            vid[i] = id;
            newp_cnt++;
         }
      }
      // add a facet between the three vertices vid[0,1,2]
      TrFace* new_f = new TrFace(vid[0], vid[1], vid[2]);
      trmesh.f_list.push_back(new_f);
   }
   else if( (int)inP.size() == 2 )
   {
      // re-order the inP, outP etc accoding to their ids.
      vector<Point> o_in_P, o_out_P;
      vector<double> o_in_val, o_out_val;
      vector<int> o_in_id, o_out_id;

      if( in_id[0] > in_id[1] )
      {
         o_in_P.push_back(inP[1]); o_in_P.push_back(inP[0]);
         o_in_val.push_back(in_val[1]); o_in_val.push_back(in_val[0]);
         o_in_id.push_back(in_id[1]); o_in_id.push_back(in_id[0]);
      }
      else if( in_id[0] < in_id[1] )
      {
         o_in_P.push_back(inP[0]); o_in_P.push_back(inP[1]);
         o_in_val.push_back(in_val[0]); o_in_val.push_back(in_val[1]);
         o_in_id.push_back(in_id[0]); o_in_id.push_back(in_id[1]);
      }
      else
         assert(0);

      if( out_id[0] > out_id[1] )
      {
         o_out_P.push_back(outP[1]); o_out_P.push_back(outP[0]);
         o_out_val.push_back(out_val[1]); o_out_val.push_back(out_val[0]);
         o_out_id.push_back(out_id[1]); o_out_id.push_back(out_id[0]);
      }
      else if( out_id[0] < out_id[1] )
      {
         o_out_P.push_back(outP[0]); o_out_P.push_back(outP[1]);
         o_out_val.push_back(out_val[0]); o_out_val.push_back(out_val[1]);
         o_out_id.push_back(out_id[0]); o_out_id.push_back(out_id[1]);
      }
      else
         assert(0);


      vector<int> new_vid;
      for(int i = 0; i < 2; i ++)
         for(int j = 0; j < 2; j ++)
         {
            // intersection point between o_in_p[i] and o_out_p[j].
            int id = -1;
            if( find_id( o_in_id[i], o_out_id[j], id ) )
               new_vid.push_back(id);
            else
            {
               Point p = get_intersection_point( o_in_val, o_out_val, o_in_P, o_out_P, i, j );
               // add the new point to the mesh.
               TrVertex* new_v = new TrVertex(p);
               trmesh.v_list.push_back(new_v);
               // record the id of this new point associated with in_id[0] and out_id[i].
               id = newp_cnt;
               set_id( o_in_id[i], o_out_id[j], id);
               new_vid.push_back(id);
               newp_cnt++;
            }
         }
      // add the facets.
      // facet 0: p0, p3, p1.
      TrFace* new_f_1 = new TrFace(new_vid[0], new_vid[3], new_vid[1]);
      trmesh.f_list.push_back(new_f_1);
      // facet 1: p0, p3, p2.
      TrFace* new_f_2 = new TrFace(new_vid[0], new_vid[3], new_vid[2]);
      trmesh.f_list.push_back(new_f_2);
   }
   else if( (int)inP.size() == 3 )
   {
      vector<int> new_vid; new_vid.resize(3,-1);
      for(int i = 0; i < 3; i ++)
      {
         // intersection point i = 0,1,2.
         int id = -1;
         if( find_id( in_id[i], out_id[0], id ) )
            new_vid[i] = id;
         else
         {
            Point p = get_intersection_point( in_val, out_val, inP, outP, i, 0 );
            // add the new point to the mesh.
            TrVertex* new_v = new TrVertex(p);
            trmesh.v_list.push_back(new_v);
            // record the id of this new point associated with in_id[0] and out_id[i].
            id = newp_cnt;
            set_id( in_id[i], out_id[0], id);
            new_vid[i] = id;
            newp_cnt++;
         }
      }
      // add the facet between p0, p1, p2.
      TrFace* new_f = new TrFace(new_vid[0], new_vid[1], new_vid[2]);
      trmesh.f_list.push_back(new_f);
   }
   else cerr << "x"; // no-op.
}