Wrap Curve To Cylinder, Pitch Blend Helices

 From:  bemfarmer
8357.1 
After many hours of study and script writing, the _WrapCurveToCyl script worked very well.

Two Helices of different pitch may have their pitches G1 Blended. This will eliminate the kink in
the join of the two helices, and eliminates kink in a swept circle. Compression spring is an example.
After sweeping a circle, the spring can be Ctrl+C copied from the MoI screen, and in Geomagic Design, a Ctrl+V pastes the Pitch Blended Helix
into GD, where it looks very nice.
Limited Flow attempts were unsuccessful. Blending the two helices directly would work, if the Bulge could be made to pass through
a point on the surface of the Cylinder. Maybe this would be possible for an improved Blend using some NewtonRaphson?

_WrapCurveToCylinder by Brian McMillin March 26, 2017.

PARAMETER DESCRIPTION:
The Front View is convenient.
This script refers to an invisible Cylinder of radius "r", with axis along the positive Z-axis. (OR CENTERED AT -RADIUS)
The "Profile" of the Cylinder is the invisible circle of radius "r", at its base.
The source curve should be 2d, and be located in the XZ plane. (2d is not required.)
Quadrant I of the XZ plane is suggested, but not essential.
The source curve could have been set up or created with an xOffsetValue greater than zero,
with xOffset = xOffsetValue * 2 * radius, which would separate cylinder from XZ curve.)
xOffset is not used at this time.
These setups could be more general, but follow conventions of the reference paper.
At present, at leaset one point should be pre-created, say at the start of the source curve,
or it could be elsewhere.

SCRIPT DESCRIPTION:
Script description with xOffset = zero (otherwise x would be replaced with (x - xOffset)):
curves located in the XZ plane, are selected, and wrapped to the Cylinder.
So z values of points on the source curve equal z values of the curve wrapped on the cylinder.
The wrapping, or mapping, is accomplished by Arraying multiple points P along the source curve.
Each point P has coordinates = (x, 0, z). (The y value is ignored.)
Note that x values are measured in radians, and that x = arclength.
ArcLenths on the Profile circle will equal x Values of the source curve.
"Theta" refers to the angles of the Profile circle of the cylinder.
Note that for a circle, ArcLength = Theta * r, so Theta = (ArcLength / r) = (x/r).

WRAPPING EQUATION for points of the new curve wrapped on the cylinder, mapped from a source curve:
Given source curve point P = (x, 0, z), Cylinder coordinates of the wrapped curve point PCyl are:
PCyl = (xPrime, yPrime, z) = ((sign * r * sin(x/r)), (r * cos(x/r)), z).
(OR y COORDINATE COULD = -1 * (r*cos(x/r) -r) )
var sign is negative for a reverse wrapped curve.
An interpcurve factory is used to connect the PCyl points, to create the new wrapped curve.

The initial purpose of this script was to connect helices of different pitches by Blending,
to remove the kink where two helices of different pitch join. There could be 2+ helices to Blend.
The two+ helices should be "in phase," of the same twist, either left had or right hand.
So each helix has been unwrapped from the helix, to the XZ plane, where portions of the
helices adjoining the join point have been Trimmed away, and Blended and joined.
The resulting curve is then to be re-Wrapped to a helix with variable pitches.
This helix will be on the surface of an invisible cylinder. Zooming way in shows considerable accuracy.

(Unwrap curve, with move and rotate, was used to unwrap the helices, for testing purposes.)

The script _UnwrapCylCurve can be used to unwrap helices.
UNWRAPPING EQUATION for points of a new 2d curve, mapped from points of a curve on a cylinder:
Given point Pcyl = (xCyl, yCyl, z), where T = xCyl,
point P = ((r * arcsin(T/r)), 0, z). An interpcurve factory will be used.

Reference is the challenging to understand trigonometry and geometry paper of Apostol and Mnatsakanian:
http://mamikon.com/USArticles/RollingConesCylinders.pdf
The paper refers to Generalized Cylinders, which may be non-circular.
The Profile of a typical Cylinder is a perpendicular Circle in the xy plane.
The Profile of a Generalized Cylinder, gCyl, is a closed curve in the xy plane.
Given a formula for the Profile curve, UnWrapping of a curve on the gCyl,
or Wrapping of a 2d curve onto the gCyl, may be do-able.
QUESTION: Since a closed curve has a NURBS formula, could a person skilled in NURBS
do an Unwrap_gCyl script, and a Wrap_gCyl script?
(FLOW test to re-Wrap a Blended pair of unwrapped helices did not work for me.)
Later I may try to use calculated arclengths to do gCyl unwrapping and wrapping.




The Black curve is the source curve, to be selected for the wrap. The green start point is the second selection.
The script can work for closed curves, and other miscellaneous curves.
Wrapped helices are Left Hand or Right hand, depending upon quadrant and Reverse Twist checkbox.
There are probably some bugs left, but the script works well for the limited testing done.

- Brian

I have not yet written _UnwrapCylCurve script.

EDITED: 28 Mar 2017 by BEMFARMER