Download

 

! ***************** trim_1 ***********************************

!

! +++

!

! Trimming of curves: Sample 1

!

!

! 2006-04-16 Gunnar Liden

!

! ---

!************************************************************

 

!sdesce Trimming of curves: Sample 1

 

GLOBAL GEOMETRY MODULE trim_1();

 

CONSTANT INT n_cur = 15; ! Number of trim curves

 

CONSTANT FLOAT d_z = 100.0; ! Delta for intersect plane

 

  INT flag_bound; ! Flag for boundary 1: Create curve

  INT i_cur;      ! Loop index curve

 

BEGINMODULE

 

! +++

! Create a surface

! ---

 

  PART(#1,lofted_fuselage(1));

 

! +++

! Coordinate system that defines the planar trim boundary

! ---

 

  POI_FREE(#7,ON(#1#1, vec(8.3, 0.1)):BLANK=1);

  POI_FREE(#8,ON(#1#1, vec(8.8, 1.1)):BLANK=1);

  POI_FREE(#9,ON(#1#1, vec(7.9, 1.9)):BLANK=1);

  CSYS_3P(#10,"CsysBound", ON(#9), ON(#7), ON(#8):BLANK=1);

 

! +++

! Start coordinate system for intersect curves

! ---

 

  POI_FREE(#4,ON(global_ref(#1#1), VEC(10, 1.6)):BLANK=1);

  CSYS_1P(#5,"IntCsysStart", ON(#4), 0.0, 0.0, 0.0:BLANK=1);

 

 

! +++

! Make some planar intersects and trim the intersect curves

! ---

 

  FOR  i_cur := 1 TO n_cur DO

    MODE_LOCAL(#5);

    CSYS_1P(#6,"IntCsys", VEC(0.0,0.0,(i_cur-1)*d_z), 0.0, 0.0, 0.0:BLANK=1);

    MODE_GLOBAL();

   

    IF N_CUR_INT(#1#1, #6) > 0 THEN

 

      CUR_INT(#3,#1#1, #6, 1);

 

      IF  i_cur = 1 THEN

        flag_bound := 1;

      ELSE

        flag_bound := 0;

      ENDIF;

 

      PART(#11,s_trim_cur(global_ref(#1#1), global_ref(#10), flag_bound,

                          global_ref(#3), 1));

     

      DEL(global_ref(#3));

 

    ENDIF;

 

    DEL(global_ref(#6));

 

  ENDFOR;

 

ENDMODULE

! ***************** trim_2 ***********************************

!

! +++

!

! Trimming of curves: Sample 2

!

!

! 2006-04-16 Gunnar Liden

!

! ---

!************************************************************

 

!sdesce Trimming of curves: Sample 2

 

 

 

GLOBAL GEOMETRY MODULE trim_2();

 

 

BEGINMODULE

 

! +++

! Create a surface

! ---

 

  PART(#1,lofted_fuselage(1));

 

 

! +++

! Coordinate system that defines the planar trim boundary

! ---

 

  POI_FREE(#7,ON(#1#1, vec(8.3, 0.1)):BLANK=1);

  POI_FREE(#8,ON(#1#1, vec(8.8, 1.1)):BLANK=1);

  POI_FREE(#9,ON(#1#1, vec(7.9, 1.9)):BLANK=1);

  CSYS_3P(#10,"CsysBound", ON(#9), ON(#7), ON(#8):BLANK=1);

 

! +++

! Create approx. trimmed surface

! ---

 

  PART(#14,trimmed_appr_sur(global_ref(#1#1), global_ref(#10), 1));

 

ENDMODULE

 

 

! ***************** s_trim_cur ****************************

!

! +++

!

! Trim a surface curve with a surface boundary curve

! defined by a planar intersect

!

! Please note that input data is not a surface boundary

! but a plane that defines the (one) boundary curve. The

! reason that intersects are made with plane and not with

! another surface curve is that intersects between surface

! curves not is very stable.

!

!

! 2006-04-16 Gunnar Liden

!

! ---

!************************************************************

 

!sdesce Trim a surface curve with a planar surface boundary curve

 

GLOBAL GEOMETRY MODULE s_trim_cur(

REF base_sur_id   >"t16 Select surface";

REF csy_bound_id  >"@t8192 Coordinate system defining boundary";

INT flag_bound:=1 >"Flag for boundary 1: Create curve";

REF i_trim_cur_id >"t8 Select curve to be trimmed";

INT graphic:=1    >"Graphic 0: Nothing 1: Curves 2: All");

 

! Internal variables

 

CONSTANT INT approx_to_cubsur = 0;

CONSTANT INT n_approx =  5;

CONSTANT INT approx_to_cubcur = 0;

 

CONSTANT INT blank_input_curve = 1;

 

 

! BLANK values for graphic

  INT bval_sur;          

  INT bval_csy;

  INT bval_cur;

  INT bval_all;

 

  REF int_id;

  REF intersect_sur_id;

  REF trim_cur_id;  

 

  INT i_branch; ! Loop index intersect curve branch

  INT n_branch; ! Number of intersect curve branches

 

  INT n_int; ! Number of intersect points

 

  VECTOR p_int; ! Intersect point

  FLOAT t_int; ! Parameter value for p_int

  FLOAT t_end; ! End parameter value for curve

 

  FLOAT t_trim_s; ! Start trim parameter value

  FLOAT t_trim_e; ! End   trim parameter value

 

 

  VECTOR p_eps_l; ! Point to determine trimmed part to keep

 

  STRING  s*1;

BEGINMODULE

 

! +++

! Initializations and check of input data

! ---

 

  IF graphic = 0 THEN

    bval_sur := 1;          

    bval_csy := 1; 

    bval_cur := 1; 

    bval_all := 1; 

  ELIF graphic = 1 THEN

    bval_sur := 1;          

    bval_csy := 1; 

    bval_cur := 0; 

    bval_all := 1; 

  ELIF graphic = 2 THEN

    bval_sur := 0;           

    bval_csy := 0; 

    bval_cur := 0;

    bval_all := 0; 

  ELSE

    EXIT("s_trim_cur: graphic not 0, 1 or 2");

  ENDIF;

 

  IF csy_bound_id = #0 THEN

   EXIT("s_trim_cur: Intersect coordinate system no defined");

  ENDIF;

 

! Initializations of local variables in order avoid crashes

! using unitialized variables

  int_id            := #0;

  intersect_sur_id  := #0;

 

! +++

! Approximate with a bicubic surface for better performance or

! if there are problems with intersections

! ---

 

  IF approx_to_cubsur = 1 THEN

    SUR_APPROX(#2,base_sur_id, "CUB_SUR", 1, n_approx:PEN=4,BLANK=bval_all);

    intersect_sur_id := GLOBAL_REF(#2);

  ELSE

    intersect_sur_id := base_sur_id;

  ENDIF;

 

! +++

! Approximate with a cubic curve for better performance or

! if there are problems with intersections

! ---

 

  IF approx_to_cubcur = 1 THEN

    CUR_APPROX(#3,i_trim_cur_id, "CUB_SEG", 1, 2:PEN=3,BLANK=bval_all);

    trim_cur_id := GLOBAL_REF(#3);

  ELSE

    trim_cur_id := i_trim_cur_id;

  ENDIF;

 

! +++

! Create the intersection curve that trims the surface

! ---

 

 IF flag_bound = 1 THEN

!  Get number of intersect branches

   n_branch := N_CUR_INT(intersect_sur_id,csy_bound_id);

   IF n_branch  = 0 THEN

     EXIT("s_trim_cur: No intersection boundary curve");

   ENDIF;

   FOR  i_branch := 1 TO n_branch DO

     CUR_INT(#4,intersect_sur_id,csy_bound_id, i_branch:PEN=2,BLANK=bval_cur);

   ENDFOR;

 ENDIF;

 

! +++

! Trim the curve

! ---

 

! End parameter value for curve

  t_end := INV_ARCL(trim_cur_id,ARCL(trim_cur_id));

 

! Number of intersect points      

  n_int := N_INTERSECT(trim_cur_id, csy_bound_id);

      

  t_int := 0.0;

! Test if curve/plane intersect exists

  IF n_int > 0 THEN

!   Use the first intersect point   

    p_int := INTERSECT(trim_cur_id,csy_bound_id, 1);

!   Parameter value for the intersect point  

    t_int := INV_ON(trim_cur_id, p_int, 1);

 

!   Blank the input curve

    IF blank_input_curve = 1 THEN

      BLANK(i_trim_cur_id);

    ENDIF;

 

!   Keep curve on the positive Z side

    POI_FREE(#9, p_int + TANG(trim_cur_id, t_int):BLANK=1);

    MODE_LOCAL(csy_bound_id);

    p_eps_l := ON(#9);

    MODE_GLOBAL();

    DEL(#9);

    IF p_eps_l.z > 0.0 THEN

      t_trim_s := t_int;

      t_trim_e := t_end;

    ELSE

      t_trim_s := 0.0;

      t_trim_e := t_int;

    ENDIF;

 

    CUR_TRIM(#1, trim_cur_id, t_trim_s, t_trim_e:BLANK=bval_cur);

    

  ENDIF;

 

 

ENDMODULE

 

! ***************** s_trim_cur ****************************

!

! +++

!

! Trim a surface curve with a surface boundary curve

! defined by a planar intersect

!

! Please note that input data is not a surface boundary

! but a plane that defines the (one) boundary curve. The

! reason that intersects are made with plane and not with

! another surface curve is that intersects between surface

! curves not is very stable.

!

!

! 2006-04-16 Gunnar Liden

!

! ---

!************************************************************

 

!sdesce Trim a surface curve with a planar surface boundary curve

 

GLOBAL GEOMETRY MODULE s_trim_cur(

REF base_sur_id   >"t16 Select surface";

REF csy_bound_id  >"@t8192 Coordinate system defining boundary";

INT flag_bound:=1 >"Flag for boundary 1: Create curve";

REF i_trim_cur_id >"t8 Select curve to be trimmed";

INT graphic:=1    >"Graphic 0: Nothing 1: Curves 2: All");

 

! Internal variables

 

CONSTANT INT approx_to_cubsur = 0;

CONSTANT INT n_approx =  5;

CONSTANT INT approx_to_cubcur = 0;

 

CONSTANT INT blank_input_curve = 1;

 

 

! BLANK values for graphic

  INT bval_sur;          

  INT bval_csy;

  INT bval_cur;

  INT bval_all;

 

  REF int_id;

  REF intersect_sur_id;

  REF trim_cur_id;  

 

  INT i_branch; ! Loop index intersect curve branch

  INT n_branch; ! Number of intersect curve branches

 

  INT n_int; ! Number of intersect points

 

  VECTOR p_int; ! Intersect point

  FLOAT t_int; ! Parameter value for p_int

  FLOAT t_end; ! End parameter value for curve

 

  FLOAT t_trim_s; ! Start trim parameter value

  FLOAT t_trim_e; ! End   trim parameter value

 

 

  VECTOR p_eps_l; ! Point to determine trimmed part to keep

 

  STRING  s*1;

BEGINMODULE

 

! +++

! Initializations and check of input data

! ---

 

  IF graphic = 0 THEN

    bval_sur := 1;          

    bval_csy := 1; 

    bval_cur := 1; 

    bval_all := 1; 

  ELIF graphic = 1 THEN

    bval_sur := 1;          

    bval_csy := 1; 

    bval_cur := 0; 

    bval_all := 1; 

  ELIF graphic = 2 THEN

    bval_sur := 0;          

    bval_csy := 0; 

    bval_cur := 0;

    bval_all := 0; 

  ELSE

    EXIT("s_trim_cur: graphic not 0, 1 or 2");

  ENDIF;

 

  IF csy_bound_id = #0 THEN

   EXIT("s_trim_cur: Intersect coordinate system no defined");

  ENDIF;

 

! Initializations of local variables in order avoid crashes

! using unitialized variables

  int_id            := #0;

  intersect_sur_id  := #0;

 

! +++

! Approximate with a bicubic surface for better performance or

! if there are problems with intersections

! ---

 

  IF approx_to_cubsur = 1 THEN

    SUR_APPROX(#2,base_sur_id, "CUB_SUR", 1, n_approx:PEN=4,BLANK=bval_all);

    intersect_sur_id := GLOBAL_REF(#2);

  ELSE

    intersect_sur_id := base_sur_id;

  ENDIF;

 

! +++

! Approximate with a cubic curve for better performance or

! if there are problems with intersections

! ---

 

  IF approx_to_cubcur = 1 THEN

    CUR_APPROX(#3,i_trim_cur_id, "CUB_SEG", 1, 2:PEN=3,BLANK=bval_all);

    trim_cur_id := GLOBAL_REF(#3);

  ELSE

    trim_cur_id := i_trim_cur_id;

  ENDIF;

 

! +++

! Create the intersection curve that trims the surface

! ---

 

 IF flag_bound = 1 THEN

!  Get number of intersect branches

   n_branch := N_CUR_INT(intersect_sur_id,csy_bound_id);

   IF n_branch  = 0 THEN

     EXIT("s_trim_cur: No intersection boundary curve");

   ENDIF;

   FOR  i_branch := 1 TO n_branch DO

     CUR_INT(#4,intersect_sur_id,csy_bound_id, i_branch:PEN=2,BLANK=bval_cur);

   ENDFOR;

 ENDIF;

 

! +++

! Trim the curve

! ---

 

! End parameter value for curve

  t_end := INV_ARCL(trim_cur_id,ARCL(trim_cur_id));

 

! Number of intersect points      

  n_int := N_INTERSECT(trim_cur_id, csy_bound_id);

      

  t_int := 0.0;

! Test if curve/plane intersect exists

  IF n_int > 0 THEN

!   Use the first intersect point   

    p_int := INTERSECT(trim_cur_id,csy_bound_id, 1);

!   Parameter value for the intersect point  

    t_int := INV_ON(trim_cur_id, p_int, 1);

 

!   Blank the input curve

    IF blank_input_curve = 1 THEN

      BLANK(i_trim_cur_id);

    ENDIF;

 

!   Keep curve on the positive Z side

    POI_FREE(#9, p_int + TANG(trim_cur_id, t_int):BLANK=1);

    MODE_LOCAL(csy_bound_id);

    p_eps_l := ON(#9);

    MODE_GLOBAL();

    DEL(#9);

    IF p_eps_l.z > 0.0 THEN

      t_trim_s := t_int;

      t_trim_e := t_end;

    ELSE

      t_trim_s := 0.0;

      t_trim_e := t_int;

    ENDIF;

 

    CUR_TRIM(#1, trim_cur_id, t_trim_s, t_trim_e:BLANK=bval_cur);

    

  ENDIF;

 

 

ENDMODULE

 

! ***************** trimmed_appr_sur ****************************

!

! +++

!

! With surface approximation, re-definition of surface parts,

! etc. can surfaces be trimmed. But it is quite a lot of work

! to do it, and the surfaces will be approximated.

!

! For this sample works sur_composite unfortunately not

! (the problem is probably a difference in parameterization)

!

!

! 2006-04-16 Gunnar Liden

!

! ---

!************************************************************

 

!sdesce Create a trimmed surface by approximation

 

GLOBAL GEOMETRY MODULE trimmed_appr_sur(

REF base_sur_id   >"t16 Select surface";

REF csy_bound_id  >"@t8192 Coordinate system defining boundary";

INT graphic:=1    >"Graphic 0: Nothing 1: Curves 2: All");

 

! Internal variables

 

CONSTANT INT blank_input_surface = 1;

 

CONSTANT INT n_u_poi = 2;

 

  VECTOR  sur_poi(30,30);

  VECTOR  sur_utan(30,30);

  INT     npu;             ! Number of U points

  INT     npv;             ! Number of V points

 

  FLOAT d_arc;     ! Delta arc

 

! BLANK values for graphic

  INT bval_sur;          

  INT bval_csy;

  INT bval_cur;

  INT bval_all;

 

  REF bound_id; ! Identity for boundary curve

  REF int_id;

  REF appr_sur_id; ! Approximative surface

  REF s_sur_id;    ! Split start surface

  REF e_sur_id;    ! Split end surface

  REF trim_id;     ! Trimmed iso-parameter

 

  REF iso_id;

 

  INT n_branch; ! Number of curve branches

 

  FLOAT  t_end;     ! End parameter for boundary curve

  INT    i_poi;     ! Loop index point on curve

  INT    n_poi;     ! Number of points to find min U

  VECTOR uv_pt;     ! U,V point

  FLOAT  u_min;     ! Minimum U value

  FLOAT  u_trim_s;  ! Trimming values

  FLOAT  u_trim_e;

  FLOAT  v_trim_s;

  FLOAT  v_trim_e;

 

 

  INT    npatu;     ! Number of patches in U direction

  INT    npatv;     ! Number of patches in V direction

 

  INT    e_npatu;   ! Number of patches in U direction

  INT    e_npatv;   ! Number of patches in V direction

 

  INT    i_cur;     ! Loop index curve

 

  INT n_int;        ! Number of intersect points

  VECTOR p_int;     ! Intersect point

  FLOAT  t_int;     ! Parameter value for p_int

 

  VECTOR  p_cur;    ! Point on trimmed isoparameter

  VECTOR  tang_cur; ! Tangent for p_cur

  FLOAT   t_cur;    ! Parameter value for p_cur

 

  CONSTANT INT   n_approx =  6;

 

BEGINMODULE

 

! +++

! Initializations and check of input data

! ---

 

  IF graphic = 0 THEN

    bval_sur := 1;          

    bval_csy := 1; 

    bval_cur := 1; 

    bval_all := 1; 

  ELIF graphic = 1 THEN

    bval_sur := 0;          

    bval_csy := 1; 

    bval_cur := 0; 

    bval_all := 1; 

  ELIF graphic = 2 THEN

    bval_sur := 0;          

    bval_csy := 0; 

    bval_cur := 0;

    bval_all := 0; 

  ELSE

    EXIT("trimmed_appr_sur: graphic not 0, 1 or 2");

  ENDIF;

 

 

! Initializations of local variables in order avoid crashes

! using unitialized variables

  bound_id := #0;

  int_id      := #0;

  appr_sur_id := #0;

  iso_id      := #0;

  trim_id     := #0;

 

 

! +++

! Approximate with a bicubic surface. It is this bicubic

! surface that will be trimmed

! ---

 

  SUR_APPROX(#2,base_sur_id, "CUB_SUR", 1, n_approx:PEN=4,BLANK=bval_all);

  appr_sur_id := #2;

 

 

! +++

! Create the intersect curve that shall trim the surface

! ---

 

 n_branch := N_CUR_INT(appr_sur_id,csy_bound_id);

 IF n_branch  = 0 THEN

   EXIT("trimmed_appr_sur: No intersection boundary curve");

 ENDIF;

 

! Use the first branch

  CUR_INT(#4,appr_sur_id ,csy_bound_id, 1:PEN=2,BLANK=bval_cur);

  bound_id := GLOBAL_REF(#4);

 

 

! +++

! Assume that the trimming are for V curves that starts in U=0

! and ends for intersect for the plane

! Determine minimum U for the curve

! ---

 

  t_end := INV_ARCL(bound_id, ARCL(bound_id));

 

  u_min := 50000000.0;

  n_poi := 30;

  FOR  i_poi := 1 TO n_poi DO

    uv_pt := EVAL(bound_id, "UV", VEC((i_poi-1)*t_end/(n_poi-1),0.0,0.0));

    IF uv_pt.x < u_min THEN

      u_min := uv_pt.x;

    ENDIF;

  ENDFOR;

 

 

! +++

! Trimming parameter values

! ---

 

  GETSURH(appr_sur_id,"NPATU",npatu);

  GETSURH(appr_sur_id,"NPATV",npatv);

 

  u_trim_s := 0.0;

 

  u_trim_e := TRUNC(u_min - 1.1) - 1.0;

  IF u_trim_e < 1.0 THEN

    EXIT("trimmed_appr_sur: trim in first patch not impl.");

  ENDIF;

 

  v_trim_s := 0.0;

  v_trim_e := npatv;

 

! +++

! Split surface with U curve

! ---

 

  SUR_TRIM(#5,appr_sur_id,u_trim_s,u_trim_e,v_trim_s, v_trim_e

              :PEN=3,BLANK=bval_sur);

  s_sur_id := GLOBAL_REF(#5);

 

  SUR_TRIM(#6,appr_sur_id, u_trim_e, npatu, v_trim_s, v_trim_e

                   :PEN=1,BLANK=bval_all);

  e_sur_id := GLOBAL_REF(#6);

 

 

! +++

! Create trimmed iso parameter curves on end split surface

! ---

 

  GETSURH(e_sur_id ,"NPATU",e_npatu);

  GETSURH(e_sur_id ,"NPATV",e_npatv);

 

  FOR  i_cur:= 1 TO 30 DO

    FOR  i_poi:= 1 TO 30 DO

      sur_poi(i_cur,i_poi) := VEC(0,0,0);

      sur_utan(i_cur,i_poi) := VEC(0,0,0);

    ENDFOR;

  ENDFOR;

 

 

  FOR  i_cur:= 1 TO e_npatv+1 DO

 

    CUR_ISO(#7,e_sur_id, "V", i_cur-1.0, 0.0, e_npatu:PEN=2,BLANK=bval_all);

    iso_id := GLOBAL_REF(#7);

 

!   Number of intersect points      

    n_int := N_INTERSECT(iso_id, csy_bound_id);

 

    t_int := 0.0;

    IF n_int > 0 THEN

!     Use the first intersect point   

      p_int := INTERSECT(iso_id,csy_bound_id, 1);

!     Parameter value for the intersect point  

      t_int := INV_ON(iso_id, p_int, 1);

      BLANK(iso_id);

      CUR_TRIM(#8, iso_id, 0.0, t_int:BLANK=bval_cur);

      trim_id := GLOBAL_REF(#8);

      DEL(iso_id);

 

      d_arc := ARCL(trim_id)/(n_u_poi-1);

 

      FOR i_poi := 1 TO n_u_poi DO

        t_cur := INV_ARCL(trim_id, (i_poi-1)*d_arc);

        p_cur :=   ON(trim_id, t_cur);

        tang_cur := TANG(trim_id, t_cur);

        sur_poi (i_poi,i_cur) := p_cur;

        sur_utan(i_poi,i_cur) := tang_cur;

      ENDFOR;

      DEL(trim_id);

 

    ENDIF;

 

  ENDFOR;

 

  IF blank_input_surface = 1 THEN

    BLANK(base_sur_id);

  ENDIF;

 

  SUR_SPLARR(#9, "ZEROTWIST_1", n_u_poi, e_npatv+1,

                  sur_poi, sur_utan:PEN=2,BLANK=0);

 

! +++

! Create the composite surface Does unfortunately not work!

! ---

 

!  sur_comp(#1, #5, #9:PEN=3,BLANK=bval_sur);

 

ENDMODULE