TUBE twisting

Viewing 10 reply threads
  • Author
    Posts
    • #3846
      Bruce Walker
      Participant

      This is a reasonably old topic on Archicad-Talk, but I thought I’d bring it up here.

      When the axis of a TUBE path changes, there are twists that occur in the profile. The specific case I have encountered was when scripting for a bent spring (such as wraps around the hose on a commercial kitchen tap). The maths works fine (and the same maths works without issue in SketchUP using Ruby with the FollowMe command), but the TUBE wants to twist. No amount of playing with the angle setting will fix this either.

      I have also tested the new TUBE{2} command, but the same issue occurs.

      Is it possible to fix this?

      The original post: https://archicad-talk.graphisoft.com/viewtopic.php?f=6&t=51395&p=277977

      Attachments:

      www.brucepwalker.com
      https://www.mindmeister.com/65450406

      AC20 6005 AUS Full & AC 21 3009 NZE Full | Win 10 Pro 64 | Intel i7-7700HQ 2.80GHz | 16 Gb RAM
      NVIDIA GeForce GTX 1060 8Mb

    • #3848
      Péter Baksa
      Keymaster

      Hi,

      The TUBE commands were designed for objects with much less twist, where some auto-correction of the profile rotation comes handy. We don’t want to fix that in the TUBE commands, that would break compatibility. There is a solution however: in a library update in version 21, the “gravity_tube” macro was added.

      As you can read in the documentation, the W axis of a cross-section at each particular node of TUBE is tied to the Z axis. With a spatial helix, this makes no sense. Using “gravity_tube”, you can set this W axis freely. In your spatial helix, this gravity vector would be pointing from the path point to the axis of the helix.

      Based on your example object, here is a sample code that models a bent helix nicely:

      resol 16
      
      ! model a helix bent 180
      mat = 45		! glass
      
      rWire	= 0.002
      rCoil	= 0.011
      nCoil	= 18		! number of turns around axis
      nTurn	= 36		! number of points in one turn
      R	= 0.1		! radius of bending
      dFi	= 180 / (nCoil * nTurn)
      
      dim axis[][3]
      dim helix[][3]
      dim gravity[][3]
      n = 0
      
      for fi = 0 to 180 step dFi
      
      	n = n + 1
      
      	! compute points as a helix on a straight cylinder, then bend it
      	aCoil = fi / dFi * (360 / nTurn)	! angle around axis
      	xCoil = cos(aCoil) * rCoil		! x, y on cylinder
      	yCoil = sin(aCoil) * rCoil
      	rTurn = R - yCoil			! turn radius of vertical line on cylinder
      
      	! helix axis point
      	axis[n][1] = 0
      	axis[n][2] = cos(fi) * R
      	axis[n][3] = sin(fi) * R
      
      	! helix point
      	helix[n][1] = xCoil
      	helix[n][2] = cos(fi) * rTurn
      	helix[n][3] = sin(fi) * rTurn
      	
      	! vector from helix to axis
      	gravity[n][1] = axis[n][1] - helix[n][1]
      	gravity[n][2] = axis[n][2] - helix[n][2]
      	gravity[n][3] = axis[n][3] - helix[n][3]
      
      next fi
      
      ! show helix
      for i = 1 to n - 1
      
      	lin_ helix[i][1], helix[i][2], helix[i][3],
      		helix[i + 1][1], helix[i + 1][2], helix[i + 1][3]
      
      next i
      
      ! show helix axis and put helix as tube path
      for i = 1 to n
      
      	hotspot axis[i][1], axis[i][2], axis[i][3]
      
      	put helix[i][1], helix[i][2], helix[i][3], 0
      
      next i
      
      ! try TUBE
      TUBE 2, n, 1 + 2 + 16 + 32,
      	0, 0, 901,
      	rWire, 360, 4001,
      	GET(NSP)
      
      ! try "gravity_tube"
      add 4 * rCoil, 0, 0
      
      ! parameters for gravity_tube (derived from TUBE{2}):
      !		top_material, bottom_material, cut_material,
      !		n, m, mask,
      !		u1, w1, s1, mat1,
      !		...
      !		un, wn, sn, matn,
      !		x1, y1, z1, angle1, gravity1_x, gravity1_y, gravity1_z,
      !		...
      !		xm, ym, zm, anglem, gravitym_x, gravitym_y, gravitym_z
      
      put mat, mat, mat,
      	2, n, 1 + 2 + 16 + 32,
      	0, 0, 901, mat,
      	rWire, 360, 4001, mat
      	
      for i = 1 to n
      
      	put helix[i][1], helix[i][2], helix[i][3], 0,
      		gravity[i][1], gravity[i][2], gravity[i][3]
      
      next i
      
      call "gravity_tube"
      
      del 1
      

      PS. “gravity_tube” might give some warnings with strict error checking options, that will be corrected in the next main release.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #3849
      Bruce Walker
      Participant

      That’s great Peter – thanks for that. I’ll give it a whirl.

      www.brucepwalker.com
      https://www.mindmeister.com/65450406

      AC20 6005 AUS Full & AC 21 3009 NZE Full | Win 10 Pro 64 | Intel i7-7700HQ 2.80GHz | 16 Gb RAM
      NVIDIA GeForce GTX 1060 8Mb

    • #3972
      Bruce Walker
      Participant

      Hi Peter,

      Finally got around to trying this out. It works…mostly. There is still one twist near the apex (see attached image). I haven’t delved into the code to figure out why. A promising result, though.

      BTW – two corrections to your code: there are two ‘next i’ nestings, and the ‘n’ in the first TUBE command doesn’t work (I replaced with NSP/4).

      www.brucepwalker.com
      https://www.mindmeister.com/65450406

      AC20 6005 AUS Full & AC 21 3009 NZE Full | Win 10 Pro 64 | Intel i7-7700HQ 2.80GHz | 16 Gb RAM
      NVIDIA GeForce GTX 1060 8Mb

    • #3981
      Péter Baksa
      Keymaster

      Hi,

      The forum engine got rid of [i] even in the code, so we turned off the italic BBCode feature. Please try the code again, now it should work.
      If you still see the twist at the apex, please write back the library version you are using. (gravity_tube has been corrected in a library update, it’s possible that your version doesn’t contain that update yet.)

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #3983
      Bruce Walker
      Participant

      Thanks Peter. The code works fine now, but there is still the twist at the apex. My library version (which says it’s up to date) is 4550.

      www.brucepwalker.com
      https://www.mindmeister.com/65450406

      AC20 6005 AUS Full & AC 21 3009 NZE Full | Win 10 Pro 64 | Intel i7-7700HQ 2.80GHz | 16 Gb RAM
      NVIDIA GeForce GTX 1060 8Mb

    • #3987
      Péter Baksa
      Keymaster

      Hi Bruce,

      there will be an NZE library update available sometime this week, that should fix this problem too.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #4728
      Nader Belal
      Participant

      @Péter Baksa,

      I need to ask a question regarding tube{2} and this macro.

      How can use an inline defined material with tube{2} and this macro ?

    • #4729
      Péter Baksa
      Keymaster

      Looks like TUBE{2} can’t do it.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

    • #18073
      Bruce Walker
      Participant

      Are there any plans to include gravity tube in the GDL command list?

      www.brucepwalker.com
      https://www.mindmeister.com/65450406

      AC20 6005 AUS Full & AC 21 3009 NZE Full | Win 10 Pro 64 | Intel i7-7700HQ 2.80GHz | 16 Gb RAM
      NVIDIA GeForce GTX 1060 8Mb

    • #18134
      Péter Baksa
      Keymaster

      No, currently that’s not planned.

      Péter Baksa
      Library Platform, Software Engineer
      GRAPHISOFT SE

Viewing 10 reply threads
  • The forum ‘3D modelling’ is closed to new topics and replies.