// The Breath Flute Project - Support Generation Module - Support.scad
//
// The Breath Flute is a wind instrument that lets players with limited musical
// experience create music using only their breath. The Breath Flute Project
// generates a Constructed Solid Geometry model in OpenSCAD for fabricating a
// Breath Flute headjoint, typically by 3D printing. The headjoint is combined
// with a body tube (e.g. 1.25" PVC) to make a complete instrument. See
// ReadMe.txt and www.BreathFlute.com for more information.
//
// This module implements several routines that generate support structures.
//
//    Written in OpenSCAD by Clint Goss [clint@goss.com]
//
// Copyright 2016-2018 the Breath Flute Project Authors (see Authors.txt).
//
// This software is part of the Breath Flute Project (www.BreathFlute.com).
// You may copy, use, modify, and distribute this software under the terms of
// the GNU General Public License version 3 ("the GPL") or any later version,
// as published by the Free Software Foundation. See the License.txt and
// GPL.txt files for details.
//
// This software is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GPL for more details.
//
// The GPL is distributed in plain text with this software. It is also
// available at <http://www.GNU.org/>.

//// beam_support
//
// Routine based on the Third-party SimpleSupport module by Brad J. Shannon
// under CC-BY. See /Src/SimpleSupport for the original code.
//
// Connect two point with a beam consisting of a cylindrical "trunk" and two cones at the tips.
//
// topPoint       The endpoints of the beam with "top" and "bottom" referring to the
// bottomPoint        Z-axis.
//
// beamDiameter   Diameter of the main trunk of the beam.
//
// topTipDiameter     Diameter of the extreme top tip of the support. This is a balance between
//                    printer nozzle size and ease of removing the supports.
// topTipHeight       Height of the top tip from the trunk of the beam.
//
// bottomTipDiameter  Diameter of the extreme bottom tip of the support.
// bottomTipHeight    Height of the bottom tip from the trunk of the beam.
//
// baseDiameter   Diameter of any additional "pedestal-style" base support.
//                Default value of 0 indicates no base.
//
// baseHeight     Height of any base support.

module beam_support (topPoint, bottomPoint, beamDiameter = 0.6,
    topTipDiameter = 0.36, topTipHeight = 0.3,
    bottomTipDiameter = 0.36, bottomTipHeight = 0.3,
    baseDiameter = 0, baseHeight = 2)
{
	// Create a pedestel, if requested
  if (baseDiameter > 0) {
		translate (topPoint) {
      cylinder (d = baseDiameter, h = baseHeight);
    }
	}
	
  // Hull together two cones to create the trunk of the beam
  
	hull () {
    topPointBias = [topPoint[0], topPoint[1], topPoint[2]-topTipHeight];
		translate (topPointBias) {
      cylinder (d1 = beamDiameter, d2 = topTipDiameter, h = topTipHeight);
    }
	
		translate (bottomPoint) {
      cylinder (d1 = bottomTipDiameter, d2 = beamDiameter, h = bottomTipHeight);
    }
	}
}

// Examples

//beam_support ([-3.3,-0.3,14], [-2.4,1.3,7.7]); // right arm
//beam_support ([3.9,0.2,9.78], [4.3,0.2,1.5]); // left arm
//beam_support ([1,-1.7,18.366], [0.4,-1.5,17.85]); // chin
