Rail3D*


 


A pair of scripts by Mark Hodson to create points with a crossing angle of 10 degrees. 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.


Right Hand

// Script to create a 10 degree right hand point

Init()
{
  node mNode=Document.GetCurrentNode();
  node Node1=mNode.GetConnectedNode(0,0);
  node Node2=mNode.GetConnectedNode(1,0);

  float x=mNode.GetX();
  float y=mNode.GetY();
  float z=mNode.GetZ();
  float alpha=mNode.GetAlpha();

  float xb=Node2.GetX();

  if(xb==0)  // Which way to go?
  {
    alpha=3.1417+alpha;
  }

  // Some useful(?) numbers
  float angle=0.1745329;  // 10 degrees
  float gauge=1.435;  // Std gauge++
  float TrackSpace=Document.GetLineSpacing();

  // Length of a 10 degree slip is 15 metres (switch to switch)
  float length=15;

  float alpha2=alpha+angle;

  // Calc position of furthest end
  float x2=x+(length*sin(alpha));
  float y2=y+(length*cos(alpha));

  // Centre
  float xc=x+((length/2.0)*sin(alpha));
  float yc=y+((length/2.0)*cos(alpha));


  // Calc position of left leg
  float x3=xc+((length/2.0)*sin(alpha2));
  float y3=yc+((length/2.0)*cos(alpha2));

  // Calc position of right leg
  float x4=xc-((length/2.0)*sin(alpha2));
  float y4=yc-((length/2.0)*cos(alpha2));

  // Build links
  Document.BuildLink(x,y,z,x2,y2,z);
  Document.BuildLink(x4,y4,z,x3,y3,z);
  Document.BuildLink(x,y,z,x3,y3,z);
  Document.DeleteNode(x4,y4);

  // Calc position from new ends

  // Extensions for required track spacing
  float SpaceLength=TrackSpace/sin(angle);
  SpaceLength=SpaceLength-length;

  x2=x2+(SpaceLength*sin(alpha));
  y2=y2+(SpaceLength*cos(alpha));

  x3=x3+(SpaceLength*sin(alpha2));
  y3=y3+(SpaceLength*cos(alpha2));
 
  float xs=x2+(SpaceLength*sin(alpha));
  float ys=y2+(SpaceLength*cos(alpha));
  Document.BuildLink(x2,y2,z,xs,ys,z);

  xs=x3+(SpaceLength*sin(alpha2));
  ys=y3+(SpaceLength*cos(alpha2));
  Document.BuildLink(x3,y3,z,xs,ys,z);
}

Left Hand

// Script to create a 10 degree left hand point

Init()
{
  node mNode=Document.GetCurrentNode();
  node Node1=mNode.GetConnectedNode(0,0);
  node Node2=mNode.GetConnectedNode(1,0);

  float x=mNode.GetX();
  float y=mNode.GetY();
  float z=mNode.GetZ();
  float alpha=mNode.GetAlpha();

  float xb=Node2.GetX();

  if(xb==0)  // Which way to go?
  {
    alpha=3.1417-alpha;
  }

  // Some useful(?) numbers
  float angle=0.1745329;  // 10 degrees
  float gauge=1.435;  // Std gauge++
  float TrackSpace=Document.GetLineSpacing();

  // Length of a 10 degree slip is 15 metres (switch to switch)
  float length=15;

  float alpha2=alpha+angle;

  // Calc position of furthest end
  float x2=x+(length*sin(alpha));
  float y2=y+(length*cos(alpha));

  // Centre
  float xc=x+((length/2.0)*sin(alpha));
  float yc=y+((length/2.0)*cos(alpha));


  // Calc position of left leg
  float x3=xc+((length/2.0)*sin(alpha2));
  float y3=yc+((length/2.0)*cos(alpha2));

  // Calc position of right leg
  float x4=xc-((length/2.0)*sin(alpha2));
  float y4=yc-((length/2.0)*cos(alpha2));

  // Build links
  Document.BuildLink(x,y,z,x2,y2,z);
  Document.BuildLink(x4,y4,z,x3,y3,z);
  Document.BuildLink(x,y,z,x3,y3,z);
  Document.DeleteNode(x4,y4);

  // Calc position from new ends

  // Extensions for required track spacing
  float SpaceLength=TrackSpace/sin(angle);
  SpaceLength=SpaceLength-length;

  x2=x2+(SpaceLength*sin(alpha));
  y2=y2+(SpaceLength*cos(alpha));

  x3=x3+(SpaceLength*sin(alpha2));
  y3=y3+(SpaceLength*cos(alpha2));
 
  float xs=x2+(SpaceLength*sin(alpha));
  float ys=y2+(SpaceLength*cos(alpha));
  Document.BuildLink(x2,y2,z,xs,ys,z);

  xs=x3+(SpaceLength*sin(alpha2));
  ys=y3+(SpaceLength*cos(alpha2));
  Document.BuildLink(x3,y3,z,xs,ys,z);
}

DanielEvans 30/09/2015 18:02:10