Best way to cut holes in pipes?

Started by samdavo, March 21, 2014, 04:27:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

prl

Sam,  obviously I'm still working on this one.  (Lucas Film studios has some interest in this one too).

Lar

Quote from: prl on March 23, 2014, 04:03:07 AM
(Lucas Film studios has some interest in this one too).
How exactly are they interested?

Lar

prl

#17
Quote from: Lar on March 23, 2014, 09:33:00 AM
How exactly are they interested?

Presumably you know that means me since I'm in the early days of inventing stupid DesignCAD gif animation tricks.  Once I get the code working to unfold the pipe, I am going to animate it too, in living color no less.  Remember I'm re-inventing the wheel.  I guess I'm at 1966 about now.



Dr PR

prl,

Are you trying to unfold the "perforated" grid? After the "Solid Subtract" the grid surface of the pipe will no longer be a single grid, but a bunch of individual polygons.

Phil
DesignCAD user since 1987

prl

Quote from: Dr PR on March 23, 2014, 09:47:56 AM
Are you trying to unfold the "perforated" grid? After the "Solid Subtract" the grid surface of the pipe will no longer be a single grid, but a bunch of individual polygons.

Yes, if I can get it to work.

Lar

Quote from: prl on March 23, 2014, 09:41:44 AM
Quote from: Lar on March 23, 2014, 09:33:00 AM
How exactly are they interested?

Presumably you know that means me
You had me on that one, Prl.

To unfold a regular grid, like a cylinder, should not be that difficult: [1] duplicate and explode into planes, the planes would have sequential entity id's... [2] select all the planes and set 3 handles at points 1, 2 and 3 of plane-1... [3] 'move' so that plane-1 is flat along one of the axis (with 'keep original scale' enabled you don't have to worry about size, just direction)... [4] deselect plane-1 and set handles on points 1, 2 and 3 of plane-2... [5] move so that handles 0 and 1 are in the same place and handle-2 is flat... Continue this 'rolling' process until all the planes are deselected, which means they are all flat.

The problem with a perforated cylinder is who knows what the sequence of the planes would be. You may have to select the planes by rolling an un-perforated exploded cylinder along with the perforated one, using the un-perforated one to determine the sequence and to drag-deselect the perforated planes (don't ever deselect the un-perforated cylinder).

An irregular grid surface would be extremely difficult to automatically determine the best way to unfold. The user would have to be involved somehow. Remember, the points of grid segments don't have to be flat like plane surfaces, meaning you may be dealing with triangular planes when the grid is exploded.

Lar

prl

#21
Quote from: Lar on March 23, 2014, 05:48:29 PM
An irregular grid surface would be extremely difficult . . .

Lar, I wouldn't know where to start with something like that.

My goal is just the cylinder with lots of holes in it.  Surprisingly, even this is trickery than I assumed.  Your outline is good.  We think alike.


Edit:  Technically I achieved the goal of making the Swiss Cheese gif movie (attached), but more than half the time my code selects the wrong things. Lots of bloopers you don't see.

I'll have to think of a different approach for finding and selecting the surfaces to move. Best to think about something else for a while.  Add it to my pile of unfinished thoughts and projects.

samdavo

#22
well - As for rolling / unrolling a cylinder, I notice Dempsey's pushapart macro has a subroutine called "MoveMyObject" - you'll find it at the end of the enclosed code ,  but I also paste it as a quote :-

QuoteMoveMyObject:
  IF ShowValues = 1 THEN
    WINDOW(10,80)
    IF group(i) > 0 THEN
      PRINT "group:", Group(i), "min/max X=(", SYS(196),SYS(198), ") Y=(", SYS(197), SYS(199), ") Z=(", SYS(200),SYS(201), ")"
    ELSE
      IF Solid(i) > 0 THEN
        PRINT "solid:", Solid(i), "min/max X=(", SYS(196),SYS(198), ") Y=(", SYS(197), SYS(199), ") Z=(", SYS(200),SYS(201), ")"
      ELSE
        PRINT "entity:", Ent(i), "min/max X=(", SYS(196),SYS(198), ") Y=(", SYS(197), SYS(199), ") Z=(", SYS(200),SYS(201), ")"
      END IF
    END IF
  END IF 
  CtrX = (SYS(196) + SYS(198)) / 2  ' center of component
  CtrY = (SYS(197) + SYS(199)) / 2
  CtrZ = (SYS(200) + SYS(201)) / 2
  DistX = CtrX - PacX   ' calculate distance
  DistY = CtrY - PacY
  DistZ = CtrZ - PacZ
  IF ExpVal >= 0 THEN   ' determine expansion factor
    Factor = ExpVal / 100
  ELSE
    Factor = ExpVal / (100 + ABS(ExpVal)) ' reverse expansion
  END IF
  DeltaX = 0  ' set actual expansion value
  IF DirX$ = "X" THEN DeltaX = DistX * Factor
  DeltaY = 0
  IF DirY$ = "Y" THEN DeltaY = DistY * Factor
  DeltaZ = 0
  IF DirZ$ = "Z" THEN DeltaZ = DistZ * Factor
  IF ShowValues = 1 THEN
    PRINT "Factor applied:", Factor
    PRINT "X from", PacX, "to", CtrX, "plus", DeltaX, "(", CtrX + DeltaX, ")"
    PRINT "Y from", PacY, "to", CtrY, "plus", DeltaY, "(", CtrY + DeltaY, ")"
    PRINT "Z from", PacZ, "to", CtrZ, "plus", DeltaZ, "(", CtrZ + DeltaZ, ")"
    PRINT "Any key to continue"
    ANYKEY
    WCLOSE
  END IF
  OrgX = Sys(190) ' get coordinates of selection handle, even if garbage values
  OrgY = Sys(191)
  OrgZ = Sys(202)
  >DragMove
    {
      <pointxyz [OrgX + DeltaX], [OrgY + DeltaY], [OrgZ + DeltaZ]
    }
RETURN

It seems to me that you could modify this "move entity" to do the following :-
a) select the set of planes (assume circular to keep it simple) - I will also go with prl's definition of the problem, i.e. that the steamroller that I drew has become a paint-roller along a length of vertical wall  (but either way)
b) calculate the angle to each plane from the axis of the roller, alpha
c) relocate each plane to a point  (alpha. Radius) along the developed direction
d) and rotate each plane by (- alpha) when it gets there.

With this method it is unlikely that the maths would give you a perfect plane of all the segments, and you might need "FlattenZ" to sort that out I guess.

And it is likely that the segments will have small gaps ( eg the 0.12etc % error I spoke of earlier), due to the difference between chordlengths and arclengths  - but this just makes it more accurate, i.e. than the "stick the planes together at their sides" - which is what I did above - reply #3. (3 cents)  - all as accurately explained by Lar incidentally.

' pushapart.d3m
'
' PURPOSE
'   To "push" the components of a 3D wood-working drawing apart such that
'   the individual components are fully visible and dimensions can be
'   added. Usually this one drawing is sufficient for constructing a
'   wood-working project instead of multiple 2D drawings (front, side and top).
'
' USAGE
'   1. MAKE SURE THAT THE MOVE/COPY "FROM REFERENCE POINT" IS UNCHECKED
'   2. Select one or more components (groups, solids, entities);
'   3. Start this macro which will prompt for three inputs and then execute;
'
' INPUTS
'   Push-apart centre -- O: drawing origin (0,0,0)
'                        C: centre of selected objects
'                        P: point to be set by user
'
'   Direction(s) of expansion -- X, Y, Z, XY, XZ, YZ, XYZ
'
'   Expansion Percentage -- nn.nn, -nn.nn
'                The centre of each selected component is pushed that
'                percentage further from the push-apart centre in the
'                direction(s) of expansion.
'                A positive expansion (e.g. 25%) can be reversed by doing the
'                same but negative expansion (e.g. -25%).
'
'   NOTE: Any nil value (carriage return or enter) will end the macro.
'
' DISCUSSION
'   Create the 3D drawing making sure that each component is how it should
'   be constructed with tenons and mortises, grooves, etc.. This is the
'   completed project 3D drawing. Each component is typically a solid.
'
'   Make a copy of that drawing and apply the push-apart.d3m macro. Start with
'   a 25% expansion for XYZ and see what it looks like. Once satisfied add
'   the dimensions and notes. This is the 3D construction drawing of
'   the project.
'
'   When in doubt about the calculated and/or used values set the flag
'   ShowValues flag to 1.
'
'   pushapart.d3m uses PUTATTR to select components, and could be slower than
'   pushapart2.d3m which uses >PointSelect to select components.
'
'   WARNING: The macro language has a dimension limit 32767 which limits
'            the number of entries that can be selected!!!
'
' HISTORY:  3-Sep-2008 Initial version, using >SetHandle and >Move
'          17-Sep-2008 Implemented negative (reverse) expansion
'          18-Sep-2008 Final version, using >DragMove
'          10-Apr-2010 Uncheck Move/Copy "From Reference Point" flag
'           6-Aug-2011 Add start/end time message
'          24-Apr-2012 Added dimension overflow protection
'------------------------------------------------------------------------------
''  INCLUDE "DcadAlias.d3i"
  SYS(36) = 2       ' silent mode
  ShowValues = 1    ' user flag; set to 1 to view values
  DebugFlag = 1     ' user flag; set to 1 to view each completed step
'
' ----- Verify that selections are made
'
  maxEnt = SYS(80)
  IF maxEnt <= 0 THEN
    MESSAGE "Nothing selected, macro will end"
    END
  ELSE
    IF maxEnt > 32767 THEN
      MESSAGE "LIMITATION: More than 32767 selected entries, macro will end"
      END
    END IF
  END IF
  DIM Ent(maxEnt)
  DIM Type(maxEnt)
  DIM Select(maxEnt)
  DIM Group(maxEnt)
  DIM Solid(maxEnt)
  DIM FindGroup(maxEnt)
  DIM nGridlines(maxEnt)

DIM Xmin(maxEnt)
Dim Xmax(maxEnt)
DIM

SYS(196) + SYS(198)) / 2  ' center of component
  CtrY = (SYS(197) + SYS(199)) / 2
  CtrZ = (SYS(200) + SYS(201)

'
' ----- Uncheck Move/Copy "From Reference Point" flag
'
  >Move
    {
      <Reference 0
      <null
    }
'
' ----- Determine push-apart centre
'
RepeatPac:
  INPUT "Push-apart centre: O = origin, C = centre of selection, P = point to be set, or <enter> = end macro", Answer$
  IF Answer$ = "" then
    END
  END IF
  Answer$ = LEFT$(Answer$, 1)
  IF (Answer$ = "O") OR (Answer$ = "o") THEN  ' use origin
    PacX = 0.0
    PacY = 0.0
    PacZ = 0.0
  ELSE
    IF (Answer$ = "C") OR (Answer$ = "c") THEN  ' use centre of selection
      PacX = (SYS(196) + SYS(198)) / 2
      PacY = (SYS(197) + SYS(199)) / 2
      PacZ = (SYS(200) + SYS(201)) / 2
    ELSE
      IF (Answer$ = "P") OR (Answer$ = "p") THEN  ' use point set by user
        SaveSys36 = SYS(36)
        SYS(36)=0
        Setpoint "Set point for push-apart centre", 1
        SYS(36) = SaveSys36
        IF SYS(1) = 0 THEN END
        Pointval PacX, PacY, PacZ, 1
        SYS(1) = 0
      ELSE
        GOTO RepeatPac
      END IF
    END IF
  END IF
'
' ----- Determine direction(s) of expansion
'
RepeatDir: 
  INPUT "Direction(s) of expansion: X, Y, Z, XY, XZ, YZ, XYZ, or <enter> = end macro", Answer$   
  IF Answer$ = "" THEN
    END
  END IF
  DirX$ = ""
  IF (INSTR(Answer$, "X") > 0) OR (INSTR(Answer$, "x") > 0) THEN DirX$ = "X"
  DirY$ = ""
  IF (INSTR(Answer$, "Y") > 0) OR (INSTR(Answer$, "y") > 0) THEN DirY$ = "Y"
  DirZ$ = ""
  IF (INSTR(Answer$, "Z") > 0) OR (INSTR(Answer$, "z") > 0) THEN DirZ$ = "Z"
  IF (DirX$ = "") AND (DirY$ = "") AND (DirZ$ = "") THEN GOTO RepeatDir
'
' ----- Determine expansion value or percentage
'
RepeatExp:
  INPUT "Expansion percentage: nn.nn, -nn.nn, or <enter> = end macro", Answer$
  IF Answer$ = "" THEN END
  ExpVal = Answer$
'
' ----- Ask for confirmation
' 
  IF ShowValues = 1 THEN
    SYS(1027) = 1                         ' OK/Cancel
    Message "push-apart centre (x, y, z) =", PacX, PacY, PacZ, chr$(13), _
            "direction(s) =", DirX$, DirY$, DirZ$, chr$(13), _
            "expansion =", ExpVal, ExpPerc$, _
            "maxEnt SYS(80) =", maxEnt
    IF SYS(1028) = 2 THEN END
  END IF
'
' ----- Save selected entities and initialize for groups (type 34)
'
  st$=sys$(7)
  FOR i = 1 TO maxEnt
    GETSELECT i, Ent(i)
    GETATTR Ent(i), Type(i), Select(i), Laynum, Group(i), Red, Green, Blue, Solid(i)
    ENTITY Ent(i)
    FindGroup(i) = 0
    IF Type(i) = 32 THEN
      nGridlines(i) = SYS(99)
    ELSE
      nGridlines(i) = 0
    END IF
  NEXT i
  >DeSelect
    {
    }
  IF DebugFlag = 1 THEN
    SYS(1027) = 1                         ' OK/Cancel
    Message "Got selected entities"
    IF SYS(1028) = 2 THEN END
  END IF
'
' ----- Untangle multi-level groups starting with the top level
'
  MoreGroups = 0
  FOR i = 1 TO maxEnt
    IF (Type(i) = 34) AND (Group(i) = 0) THEN   ' top-level group
      ENTITY Ent(i)
      Group(i) = SYS(91)
      FOR j = 1 TO MaxEnt   ' look for subgroup(s)
        IF (Type(i) = 34 ) AND (Group(j) = Group(i)) THEN
          ENTITY Ent(j)
          FindGroup(j) = SYS(91)
          MoreGroups = 1
        END IF
      NEXT j
      FindGroup(i) = 0
    END IF
  NEXT i
  IF DebugFlag = 1 THEN
    SYS(1027) = 1                         ' OK/Cancel
    Message "Got multi-level groups"
    IF SYS(1028) = 2 THEN END
  END IF
'
' ----- Change group ID to that of the top-level
'
  DO WHILE MoreGroups > 0
    MoreGroups = 0
    FOR i = 1 TO maxEnt
      IF (Type(i) = 34) AND (FindGroup(i) > 0) THEN
        FOR j = 1 TO MaxEnt
          IF Group(j) = FindGroup(i) THEN
            IF Type(j) = 34 THEN
              ENTITY Ent(j)
              FindGroup(j) = SYS(91)
              MoreGroups = 1
            END IF
            Group(j) = Group(i)
          END IF
        NEXT j
        FindGroup(i) = 0
      END IF
    NEXT i
  LOOP
  IF DebugFlag = 1 THEN
    SYS(1027) = 1                         ' OK/Cancel
    Message "Normalized multi-level groups to top-level group"
    IF SYS(1028) = 2 THEN END
  END IF
'
' ----- Select a group, a solid or an individual entity
'       Select(i) is set to 0 when the entity has been processed
'   
  FOR i = 1 TO maxEnt
    IF (Select(i) > 0) THEN
      IF Group(i) > 0 THEN   ' select all entities of a group
        Grp = Group(i)
        iGrp = i
        IF DebugFlag = 1 THEN
          SYS(1027) = 1                         ' OK/Cancel
          Message "Pushed group", Grp
          IF SYS(1028) = 2 THEN END
        END IF
        GOSUB SelectMyGroup
      ELSE
        IF Solid(i) > 0 THEN   ' select all entities of a solid
          Sld = Solid(i)
          iSld = i
          IF DebugFlag = 1 THEN
            SYS(1027) = 1                         ' OK/Cancel
            Message "Pushed solid", Sld
            IF SYS(1028) = 2 THEN END
          END IF
          GOSUB SelectMySolid
        ELSE    ' select remaining entities individually
          PUTATTR Ent(i), Type(i), 1
          Select(i) = 0
          IF DebugFlag = 1 THEN
            SYS(1027) = 1                         ' OK/Cancel
            Message "Pushed entity", Ent(i)
            IF SYS(1028) = 2 THEN END
          END IF
        END IF
      END IF
'
' ----- Calculate centre of object and move to new location
'
      GOSUB MoveMyObject
      >DeSelect
        { 
        }
    END IF
  NEXT i
'
' ----- Re-select entities again for a clean exit
'
  FOR i = 1 TO maxEnt
    PUTATTR Ent(i), Type(i), 1
    IF (Type(i) = 32) AND (nGridLines(i) > 0) THEN
      LastGridLine = Ent(i) + nGridlines(i)
      FOR k = Ent(i)+1 TO LastGridLine
        GETATTR k, TypeGrid
        PUTATTR k, TypeGrid, 1
      NEXT k
    END IF
  NEXT i
  IF DebugFlag = 1 THEN
    SYS(1027) = 1                         ' OK/Cancel
    Message "Reselected entities and exit"
    IF SYS(1028) = 2 THEN END
  END IF
'
  SYS(36)=0   ' normal mode
  REGEN
  et$ = sys$(7)
  message "end time", et$, chr$(13), "start time", st$
  END
'
' ----- Subroutines
'
SelectMyGroup:
  FOR g  = iGrp TO maxEnt
    ENTITY Ent(g)
    IF (Group(g) = Grp) THEN
      IF Solid(g) > 0 THEN
        Sld = Solid(g)
        iSld = g
        GOSUB SelectMySolid
      ELSE
        PUTATTR Ent(g), Type(g), 1
        Select(g) = 0
      END IF
    END IF
  NEXT g
RETURN
'
'
SelectMySolid:
  FOR s = iSld TO maxEnt
    IF Solid(s) = Sld THEN
      PUTATTR Ent(s), Type(s), 1
      Select(s) = 0
      IF (Type(s) = 32) AND (nGridLines(s) > 0) THEN
        LastGridLine = Ent(s) + nGridlines(s)
        FOR k = Ent(s)+1 TO LastGridLine
          GETATTR k, TypeGrid
          PUTATTR k, TypeGrid, 1
        NEXT k
      END IF
    END IF
  NEXT s
RETURN
'
'
MoveMyObject:
  IF ShowValues = 1 THEN
    WINDOW(10,80)
    IF group(i) > 0 THEN
      PRINT "group:", Group(i), "min/max X=(", SYS(196),SYS(198), ") Y=(", SYS(197), SYS(199), ") Z=(", SYS(200),SYS(201), ")"
    ELSE
      IF Solid(i) > 0 THEN
        PRINT "solid:", Solid(i), "min/max X=(", SYS(196),SYS(198), ") Y=(", SYS(197), SYS(199), ") Z=(", SYS(200),SYS(201), ")"
      ELSE
        PRINT "entity:", Ent(i), "min/max X=(", SYS(196),SYS(198), ") Y=(", SYS(197), SYS(199), ") Z=(", SYS(200),SYS(201), ")"
      END IF
    END IF
  END IF 
  CtrX = (SYS(196) + SYS(198)) / 2  ' center of component
  CtrY = (SYS(197) + SYS(199)) / 2
  CtrZ = (SYS(200) + SYS(201)) / 2
  DistX = CtrX - PacX   ' calculate distance
  DistY = CtrY - PacY
  DistZ = CtrZ - PacZ
  IF ExpVal >= 0 THEN   ' determine expansion factor
    Factor = ExpVal / 100
  ELSE
    Factor = ExpVal / (100 + ABS(ExpVal)) ' reverse expansion
  END IF
  DeltaX = 0  ' set actual expansion value
  IF DirX$ = "X" THEN DeltaX = DistX * Factor
  DeltaY = 0
  IF DirY$ = "Y" THEN DeltaY = DistY * Factor
  DeltaZ = 0
  IF DirZ$ = "Z" THEN DeltaZ = DistZ * Factor
  IF ShowValues = 1 THEN
    PRINT "Factor applied:", Factor
    PRINT "X from", PacX, "to", CtrX, "plus", DeltaX, "(", CtrX + DeltaX, ")"
    PRINT "Y from", PacY, "to", CtrY, "plus", DeltaY, "(", CtrY + DeltaY, ")"
    PRINT "Z from", PacZ, "to", CtrZ, "plus", DeltaZ, "(", CtrZ + DeltaZ, ")"
    PRINT "Any key to continue"
    ANYKEY
    WCLOSE
  END IF
  OrgX = Sys(190) ' get coordinates of selection handle, even if garbage values
  OrgY = Sys(191)
  OrgZ = Sys(202)
  >DragMove
    {
      <pointxyz [OrgX + DeltaX], [OrgY + DeltaY], [OrgZ + DeltaZ]
    }
RETURN

samdavo

#23
Whilst I am at it, just a bit of artwork :)
but this is what I got when I used pushapart and exploded the 3m diam pipe to 9m diam.

prl

#24
Quote from: samdavo on March 24, 2014, 10:37:11 AM
Whilst I am at it, just a bit of artwork :)

Nice, I always try to see the interesting in the odd things we do. 

For DesignCAD history buffs, I attach DesignCAD's first blooper.  Rare footage of a magic routine gone wrong.

Blooper #1

samdavo


Bob P

As I see it, it's easy to explode the components, but re-assembling them could get messy if the entity numbers weren't consistent where the segments were cut into pieces.  I thought of searching for a previous edge whose length matched one on the working segment, but that could easily blow up.  In addition, going from a two-part segment (that's been cut in two) to a single-part segment makes things even more complicated.

samdavo

#27
Bob - sure, but that's why I'm proposing locating each a distance (alpha.rad) along the rolling direction.  i.e. the segments don't have to join even.  :)  (2 cents)

PS It's currently 5.40 am - and I thought of that about an hour ago.  Couldn't sleep - what with Dempsey's macro going round and round in my head lol.  (endless looping lol).

I'll repeat the important bit of post #22 :-
QuoteIt seems to me that you could modify this "move entity" to do the following :-
a) select the set of planes (assume circular to keep it simple) - I will also go with prl's definition of the problem, i.e. that the steamroller that I drew has become a paint-roller along a length of vertical wall  (but either way)
b) calculate the angle to each plane from the axis of the roller, alpha
c) relocate each plane to a point  (alpha. Radius) along the developed direction
d) and rotate each plane by (- alpha) when it gets there.

I suppose in summary I'm saying that it would be easier to get away from XYZ, and start talking polar coordinates.

prl

Quote from: Bob P on March 24, 2014, 11:06:52 AM
going from a two-part segment . . . .makes things even more complicated.

Yes, you identified the difficulty.  The vertical segments where the holes occur (may be more than one), are not sequential.  Easy to grab the wrong one.

samdavo

#29
Quote from: Dean on March 22, 2014, 06:16:43 PM
This is how I'd do it.
An un-wrapping of the pipe face would be great feature but can't you just do the math and draw it?
Dean I owe you an apology - (my reply to your post #10) - in that the curved pipe actually adds a massive degree of difficulty.   

But you (or I) could make it harder still - getting away from radial intersecting pipes, and using tangential instead... eg with this contraption, which I guess could be called a heat exchanger (?)

PS for a start, I suspect (from the closeup) that my degree of fineness (whatever it's called) could be reviewed to advantage - to smooth out the sawtooth edge there. (But having said that, a fitter with an oxytorch is not gonna worry about millimetres :) - blind man, galloping horse,  etc.)

PS looking at that, I'm thinking it would be easier to cut the top half of  the green pipe out of a cardboard tube, and trace it on the curved pipe lol.