DesignScript

## DesignScript

*Expert Elite*
Posts: 2,072
Registered: ‎04-29-2006
Message 1 of 5 (386 Views)

# Some more curves

386 Views, 4 Replies
10-24-2012 03:26 AM

Hi,

DesignScript is relatively poor in native curves (Line, Arc, Circle and BSplineCurve).
I thought it might be interesting to define some others.
I tried to do this as classes with constructors, these classes may be required to evolve with the addition of new features.
The
generated curves are spline whose control points or smoothing are calculated from the equations of these curves.

The Catenary, Ellipse, EllpticalArc and Parabola classes:

import("ProtoGeometry.dll");
import("Math.dll");

class Catenary
{
Curve : Curve;
Chord : double;
Param : double;
Sagitta : double;
Length : double;

def argCosh(x : double)
{
return = Math.Log(x + Math.Sqrt(x * x - 1));
}

constructor FromChordParam(chord : double, param : double, numPts : int)
{
Chord = chord;
Param = param;
Sagitta = param * Math.Cosh(chord / (2 * param)) - param;
Length = 2 * param * Math.Sinh(chord / (2 * param));
x = chord / -2..chord / 2..#numPts;
y = param * Math.Cosh(x / param);
Curve = BSplineCurve.ByPoints(Point.ByCoordinates(x, y, 0));
}

constructor FromLenthSagitta(length : double, sagitta : double, numPts : int)
{
Length = length;
Sagitta = sagitta;
Param = (length * length - 4 * sagitta * sagitta) / (8 * sagitta);
Chord = 2 * Param * argCosh((sagitta + Param) / Param);
x = Chord / -2..Chord / 2..#numPts;
y = Param * Math.Cosh(x / Param);
Curve = BSplineCurve.ByPoints(Point.ByCoordinates(x, y, 0));
}
{
Curve : Curve;
Focus : Point;

constructor FromChordSagitta(chord : double, sagitta : double, numPts : int, focusVisible : bool)
{
a = 4 * sagitta / (chord * chord);
Focus = Point.ByCoordinates(0, 1 / (4 * a), 0).SetVisibility(focusVisible);
x = chord / - 2..chord / 2..#numPts;
y = a * x * x;
Curve = BSplineCurve.ByPoints(Point.ByCoordinates(x, y, 0));
}
}

Using examples

Ellipses with incremented major axis.

Parabolas with decremented chords and incrmented sagittas.

parabs = Parabola.FromChordSagitta(200..100..-10, 20..120..10, 19, false);

Catenaries with incremented params.

Each curve is moved so that start and end point lies ont the X axis. This is done using the Param and Sagitta properties of the Catenary instance.

def catenar(chord : double, param : double, numPts : int)
{
cat = Catenary.FromChordParam(chord, param, numPts);
return = cat.Curve.Translate(0, -cat.Param - cat.Sagitta, 0);
}

cats = catenar(160, 35..75..#10, 19);

Gilles Chanteau
Member
Posts: 5
Registered: ‎10-20-2012
Message 2 of 5 (378 Views)

# Re: Some more curves

10-24-2012 06:08 AM in reply to: _gile

Thanks!

These definitions are very useful.

Active Member
Posts: 7
Registered: ‎09-26-2012
Message 3 of 5 (335 Views)

# Re: Some more curves

10-30-2012 04:29 PM in reply to: _gile

This is great! How did you find writing your own classes? Any surprises?

Luke

*Expert Elite*
Posts: 2,072
Registered: ‎04-29-2006
Message 4 of 5 (324 Views)

# Re: Some more curves

10-31-2012 02:26 PM in reply to: luke

Thanks Luke.

I found an example of class in the tutorial and try to build my own ones.

Gilles Chanteau
*Expert Elite*
Posts: 2,072
Registered: ‎04-29-2006
Message 5 of 5 (314 Views)

# Re: Some more curves

11-01-2012 11:37 AM in reply to: _gile

One more: a cylindrical helix.

The constructor arguments are:

• the total height
• the total angle, if the input is negative the helix turns clockwise
import("ProtoGeometry.dll");
import("Math.dll");

class Helix
{
Curve : Curve;
{
pi = 3.141592653589793;
numPts = Math.Abs(Math.Round(totalAngle / 15)) + 1;
step = height / (numPts - 1);
ccw = Math.Sign(totalAngle);
tanZ = (180 * height) / (pi * totalAngle * radius);
startTan = Vector.ByCoordinates(0, ccw, ccw * tanZ);
endTan = Vector.ByCoordinates(ccw * -Math.Sin(totalAngle), ccw * Math.Cos(totalAngle), ccw * tanZ);
x = radius * Math.Cos(0 .. totalAngle .. #numPts);
y = radius * Math.Sin(0 .. totalAngle .. #numPts);
z = step * (0 .. numPts);
Curve = BSplineCurve.ByPoints(Point.ByCoordinates(x, y, z), startTan, endTan);
}
}

Gilles Chanteau

### You are not logged in.

Announcements
Visit Autodesk Labs
Autodesk Labs is home for new prototypes, experiments, applications, and technologies.