POV-Ray : Newsgroups : povray.text.scene-files : Catenary - a chain making macro Server Time
31 Oct 2024 19:30:53 EDT (-0400)
  Catenary - a chain making macro (Message 1 to 1 of 1)  
From: PM 2Ring
Subject: Catenary - a chain making macro
Date: 2 Sep 2005 06:45:00
Message: <web.43182c9b30c60c8bbc2b06b10@news.povray.org>
Here are the contents of Catenary.zip, which appears to be corrupt.

**********
README.TXT
**********

This archive contains a chain-making macro for the POV-Ray ray-tracer.

The Chain() macro makes a catenary, the proper curve of a homogeneous chain.
See Catenary.txt for instructions.

----------------------------------------------------------------------------------------

File          Contents                Size (bytes)
----          --------                ----
readme.txt    this file.              1292
Catenary.inc  the Chain() macro       7794
Catenary.txt  the reference manual    2750
Catenary.pov  a short test scene      3132
                                      ----
                             Total   14968

----------------------------------------------------------------------------------------

The software in this archive was created by PM 2Ring and may be freely used
and modified,
as long as credit is given.

This software was inspired by Chris Colefax's "link.inc", which makes
parabolic chains.
Catenary parameter calculations thanks to Zdislav V. Kovarik. See
Catenary.inc for details.

----------------------------------------------------------------------------------------

*********
CHAIN.TXT
*********

C H A I N

chain.txt  - reference manual for Chain(), a POV-Ray macro.
Created by PM 2Ring July-August 2005.

The Chain() macro makes a catenary, the proper curve of a homogeneous chain.
The main parameters are: the link object itself, the start and end points of
the chain,
and the chain slackness. Other parameters allow some fine-tuning of the
layout of the chain.
_______________________________________________________________________________

Chain(Link, Start, End, Slack, Overlap, Alternate, AltPhase, Twist,
StartSkip, EndSkip, OddLinks)

Parameters:

Link
The Link object.
One link of the chain. The chain is a union of these links with their x-axes
running along the chain.
In other words, at the centre of each link, the x-axis of the link is
tangential to the catenary.
The Link object is used as-is, no scaling is applied.

Start
The Start point.
The co-ordinates of the centre of the first link in the chain.

End
The End Point.
The co-ordinates of the centre of the last link in the chain.

Slack
The Slackness of the chain.
Slack is calculated as the chain length divided by the straight-line
distance between the Start and End points.
Slack must be greater than 1. The length will be adjusted upwards internally
to ensure a whole number of links.

Overlap
The link Overlap.
The link length is internally divided by the Overlap. With Overlap = 1, the
links just touch end to end,
so in a realistic chain Overlap will be around 1.5, depending on the
thickness of the links.

Alternate
Alternating 90 degree twist on the X-axis.
With Alternate equal to 1, adjacent links are aligned to each other with the
usual 90 degree X-axis twist seen
in normal chains. With Alternate equal to 0, no twist is applied. Other
values may be used for odd effects.

AltPhase
The starting Phase of Alternation.
Select whether odd or even links are given the Alternating twist on the
X-axis.
Only has effect if Alternate is non-zero.

Twist
Extra X-axis Twist on the whole chain.
Twist is given in whole cycles, so a Twist of 1 causes the chain to be
twisted by 360 degrees from start to finish.
This Twist is in addition to any twist specified by Alternate.

StartSkip
The number of links to Skip at the Start of the chain.
These links are simply deleted from the chain. This doesn't affect any of
the other calculations.

EndSkip
The number of links to Skip at End of the chain.
These links are simply deleted from the chain. This doesn't affect any of
the other calculations.

OddLinks
Force the total number of Links in the chain to be Odd, for symmetry
reasons.

_______________________________________________________________________________

************
CATENARY.INC
************

// Persistence of Vision Ray Tracer Include File
// File: Catenary.inc
// Desc: Proper catenary chain. Version 1.0
// Date: 2005.07.30
// Auth: PM 2Ring
//
// Catenary parameter calculations thanks to Zdislav V. Kovarik. See below
//
// For instructions, please see "Catenary.txt"
//
//-------------------------------------------------------------------------

#ifndef(Catenary_Inc_Temp)
#declare Catenary_Inc_Temp=version;
#version 3.6;

#ifdef(View_POV_Include_Stack)
  #debug "including Catenary.incn"
#end

//-------------------------------------------------------------------------
//
// From: kov### [at] mcmailcisMcMasterCA (Zdislav V. Kovarik)
// Subject: Re: Catenary
// Date: 5 Nov 1999 14:33:22 -0500
// Newsgroups: sci.math
// Keywords: fitting a catenary to match a suspended cable
//
// Upright catenary:  y - y_0 = a * cosh((x - x_0)/a) ,  a > 0.
// The vertex is (x_0, y_0+a).
// The parameter a turns out to be the radius of curvature at the vertex.
// Remark: The radius of curvature at a point above x is
//   a * (cosh((x-x_0)/a)^2.
//
// Problem: Parameters a, x_0, y_0 to be found so that the catenary arc
passes
// through (x_1, y_1), (x_2, y_2) and has length L between these points
// (provided L > sqrt((x_2 - x_1)^2 + (y_2 - y_1)^2) )
//
// The equations to be solved are (after some symmetrizing manipulation
// of the arclength integral)
//
//   y_1 - y_0 = a * cosh ((x_1 - x_0)/a)
//   y_2 - y_0 = a * cosh ((x_2 - x_0)/a)
//   2*a * cosh((x_1 + x_2 - 2*x_0)/(2*a)) * sinh((x_2 - x_1)/(2*a)) = L
//
// and it can be reduced to solving for one unknown at a time.
//
// First, we introduce an auxiliary unknown z which is to satisfy
//
//   sinh(z) / z = sqrt(L^2 - (y_2 - y_1)^2) / abs(x_2 - x_1)  ,   z > 0
//
// (the only transcendental non-elementary equation)
// and then the unknowns pop out:
//
//     a = abs(x_2 - x_1) / (2*z)
//   x_0 = (1/2)*(x_1 + x_2 - a * ln ((L + (y_2 - y_1)) / (L - (y_2 - y_1)))
//   y_0 =  (y_1 + y_2)/2 - (L/2) * coth(z).
//
//-------------------------------------------------------------------------

// Find B such that A=sinh(B)/B. Named in parallel to sinc()
#macro asinch(A)
  #local B = sqrt(6*max(1e-4,A-1));   //1st approx, from sinh(B) = B +
B^3/3! + ...
  #local B = asinh(A*B);              //2nd approx, from sinh(B) = A*B

  #local MI = 8;
  #local I = 0;
  #while(I<MI)                         //Newton's method
    #local S = sinh(B);
    #local C = B * cosh(B);
    #local M = (A*B + C - 2*S) / (C - S);
    #local B = B * M;
    #local I = I + 1;
    #if(abs(M-1)<1e-12)               //bailout
      #local I = MI;
    #end
  #end
  B                                   //return value
#end

//Find width of an object's bounding box
#macro BBWidth(A) (max_extent(A) - min_extent(A)).x #end

// Make a catenary. Parameters: Link object, Start point, End Point,
// Slackness of the chain >1, Link overlap, Extra twist on whole cable,
// Alternate 90 degree twist on X-axis, Starting phase of Alternation,
// Links to Skip at start, Links to Skip at end, Make number of links odd
#macro Chain(Link, StartA, EndA, Slack, Overlap, Alternate, AltPhase, Twist,
StartSkip, EndSkip, OddLinks)
  //Temporarily translate Start point to origin & work in XY plane
  #local End = EndA - StartA;
  #local TH = degrees(atan2(End.z, End.x));
  #local End = vrotate(End, y*TH);              //Rotate to positive x-axis

  //Find required chain length and number of links
  #local Len = vlength(End) * Slack;            //Basic chain length
  #local LL = BBWidth(Link) / Overlap;          //Link Length adjusted for
link overlap

  #local Steps = ceil(Len/LL);                  //Number of links minus one,
to account for half-links at each end
  #if(OddLinks)                                 //Round up to next even
integer
    #local Steps = 2*ceil(.5*Steps);
  #end
  #local Len = Steps * LL;                      //Adjusted chain length

  //Find vertex of catenary that connects <0,0,0> & End, with length Len.
  #local P = sqrt(Len*Len - End.y*End.y) / End.x;
  #local Q = asinch(P);
  #local A = End.x / (2*Q);                     //Catenary curvature
parameter.

  #local X = A * ln((Len + End.y) / (Len - End.y));
  #local Y = Len/tanh(Q);
  #local V = (End - <X, Y, 0>)*.5;              //Vertex - a*y
  #local S1 = A*sinh(V.x/A);                    //Arclength at vertex

  //Step evenly along catenary parametrized by arclength.
  union {
    #local I = StartSkip;
    #while (I <= Steps - EndSkip)
      #local S = LL * I - S1;                   //Arclength from Vertex
      #local M = S / A;                         //Slope of tangent
      #local X = asinh(M);
      #local Y = sqrt(1 + M*M);

      object{
        Link
        rotate (Alternate*90*mod(I+AltPhase,2) + Twist*360*I/(Steps-1))*x
        rotate z*degrees(atan(M))               //Rotate parallel to tangent
        translate V + A*<X, Y, 0>
      }
      #local I = I + 1;
    #end

    //Transform back
    rotate -y*TH
    translate StartA
  }
#end

#version Catenary_Inc_Temp;
#end

//-------------------------------------------------------------------------

************
CATENARY.POV
************


// Persistence of Vision Ray Tracer Scene Description File
// File: Catenary.pov
// Desc: Testing Catenary include file
// Date: 2005.07.30
// Auth: PM 2Ring
//
// Catenary parameter calculations thanks to Zdislav V. Kovarik
// See Catenary.inc for details.
//
// For instructions, please see "Catenary.txt"
//
//-------------------------------------------------------------------------
//
// -f -A0.5 +AM2 +R1
// +A0.15 +AM2 +R3
//

#include "finish.inc"
#include "metals.inc"

//Chain making macro
#include "Catenary.inc"

global_settings {
  assumed_gamma 1.0
  max_trace_level 10
}

//-------------------------------------------------------------------------

//Simple chain macro. Parameters: Start point,End Point. Make sure other
items are declared before calling!
#macro ChainQ(Start, End)
  Chain(Link, Start, End, Slack, Overlap, Alternate, AltPhase, Twist,
StartSkip, EndSkip, OddLinks)
#end

//Chain terminal post
#macro Terminal(Pos)
union{
  sphere{Pos, PostRad*1.75}
  cylinder{Pos*<1,0,1>, Pos-0.35*PostRad*y, PostRad}

  pigment{rgb <.2, .5, 1>}
  finish{Glossy}
}
#end

//Chain, with terminal at start
#macro TermChain(Start, End)
  Terminal(Start)
  ChainQ(Start, End)
#end

//Link object
#declare Torus = torus {.75, .175 scale 0.15*<1, 1, .65> texture{T_Gold_3D}}

//--- The scene -----------------------------------------------------------

#declare Rad = 2.0;               //Scene size control
#declare PostRad= 0.150;          //Post radius

//Chain parameters
#declare Link = Torus;            //Link object

#declare Slack = 1.10;            //Slackness of the chain. (Length of
chain) / (straight distance between points)
#declare Overlap = 1.65;          //Link overlap
#declare Twist = 0;               //Chain twist (in cycles)

#declare Alternate = 1;           //Rotate Alternate links by 90*x
#declare AltPhase = 1;            //First link rotated by 90*x
#declare StartSkip = 2;           //Skip first 2 links
#declare EndSkip = StartSkip;     //Skip last 2 links
#declare OddLinks = 1;            //Use an odd number of links

//Some points to connect
#declare V1 = < 1.5*Rad, 1.5*Rad, 2>;
#declare V2 = < 0, 1.25*Rad, 4>;
#declare V3 = <-1.5*Rad, 1.0*Rad, 1>;
#declare V4 = < 0, 0.75*Rad, 0>;

TermChain(V1, V2)
TermChain(V2, V3)
TermChain(V3, V4)
TermChain(V4, V1)

//Simple room with checkered floor
#declare WS = 5*Rad;
box{<-1, -2/WS, -2>, <1, 3, 2> scale WS inverse pigment{gradient y scale
3.001*WS}finish{Shiny}}
box{<-1, -1/WS, -2>, <1, 0, 2> scale WS pigment{checker rgb 1,rgb
...05}finish{Glossy diffuse 0.80}}

camera {
  location <0.25, 3.5, -5.5> * Rad
  look_at  y*1.6

  right x*image_width/image_height up y
  direction z

  angle 32
}

light_source {
  <1, 9, -3>*Rad rgb 1.75
  spotlight point_at z*2 falloff 15 radius 4
}

//-------------------------------------------------------------------------


Post a reply to this message


Attachments:
Download 'catenary.inc.txt' (8 KB)

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.