A script by Mark Hodson that creates a curve of the specified angle, dividing it up into the given number of sections. The starting node must be selected before the script is called, and the script then works out which end of the node is free and creates the sections from there. A positive angle specifies a left-hand curve, and a negative angle a right hand one.
// Script to create a series of arc segments
// Mark Hodson 31.01.2007 for Rail3D.2kd 101.1
Init()
{
node mNde=Document.GetCurrentNode();
node mNde1=mNde.GetConnectedNode(0,0);
node mNde2=mNde.GetConnectedNode(1,0);
node mNde3; //temporary node
float radians=3.1416/180;
float R=InputFloat("Radius in metres"); //Radius in metres
int nsteps=InputInt("No. of steps"); //number of segments to make
float totAngle=InputFloat("Total angle in degrees (+ for left, - for right)");
//the variable "sign" is set to -1 if the curve is to the right
float sign=1;
if(0.0>totAngle)
{
sign=-1;
totAngle=sign*totAngle;
}
//degrees per track section
float AngStep=totAngle/nsteps;
//Get the coordinates of the start node
float x=mNde.GetX();
float y=mNde.GetY();
float z=mNde.GetZ();
float alpha=mNde.GetAlpha();
//find centre of circle
float x0=x-(sign*R*cos(alpha));
float y0=y+(sign*R*sin(alpha));
//check if the node is connected on both sides
float xb=mNde2.GetX();
if(xb==0) // Which way?
{
alpha=3.1416+alpha;
}
int a=1; //counter for steps
//coordinates of working points
float x1;
float y1;
float x2=x;
float y2=y;
float theta;
//repeat for each segment
while(a<(nsteps+1))
{
theta=alpha+(sign*(90-(a*AngStep))*radians);
x1=R*sin(theta)+x0;
y1=R*cos(theta)+y0;
Document.BuildLink(x2,y2,z,x1,y1,z);
mNde3=Document.GetNode(x1,y1);
mNde3.SetAlpha((-90*sign*radians)+theta);
x2=x1;
y2=y1;
a++;
}
}
DanielEvans 30/09/2015 18:01:53