POV-Ray : Newsgroups : povray.general : HELP - Rotating Railing Posts around Scaled Cylinder Edge : Re: HELP - Rotating Railing Posts around Scaled Cylinder Edge Server Time
28 Apr 2024 09:24:04 EDT (-0400)
  Re: HELP - Rotating Railing Posts around Scaled Cylinder Edge  
From: Tor Olav Kristensen
Date: 30 Mar 2018 11:20:00
Message: <web.5abe546386273580e891b8fb0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> That's a very nice construction, TOK!  :)

Thank you Bill :)


> It took me a minute look it all over and see what was going on - the diagram and
> animation on that page really help.

Yes, that animation helped me much too.


> It's so nice to have many different ways to construct the same shape, but with
> different results in the point-by-point details.

I Agree. And as you have probably noticed, I'm find it interesting when problems
like these can be solved without trigonometry.


> I'll need to look at TdG's code, but it seems to be very similar to a way I was
> thinking of that would show how the ellipse is the uneven scaling of a circle.
>
> With radius and angle, use transforms to "move" a vector to a place on the
> circle, then using scaling transforms, adjust it to be elliptical.
> Then an "overall scaling" transform could be applied after that as well.

Yes, that is a possible way of doing it. But if Sven wants to place the fence
posts evenly along his elliptic shape, then that way is more problematic,
because the distances between the posts will then wary quite much.

I see now that it was you that linked to the Wikipedia page. Christoph linked to
a StackExchange page. Sorry about that.

And on that StackExchange page Dr. Martin von Gagern mentions that a way to
calculate the coordinates of such evenly distributed points is to calculate
complete and incomplete elliptic integrals of the second kind and then do some
numerical solving (and more). I started to make code for that, but before I
finished it I found that an it could be done with much less effort in POV-Ray
with some more linear splines. (My way may not be not as good as MvG's solution,
but I suspect that it is good enough for Sven's purpose.) See the code below for
this.

Tor Olav
http://subcube.com

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7
// Distributing points evenly around an ellipse
// By Tor Olav Kristensen
// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#version 3.7;

#include "colors.inc"

global_settings { assumed_gamma 1.0 }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare T = 0.010; // Height of elliptic cylinder
#declare D = 0.011; // Height of the small sylinders
#declare R = 0.04; // Radius of the small cylinders

#declare A = 2; // Semi-major axis
#declare B = 1; // Semi-minor axis

cylinder {
    -T*y, +T*y, 1
    scale <A, 1, B>
    pigment { color Blue }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare Nil = 1e-9;
#declare Spline1 =
    spline {
        linear_spline
        0.00      , <+A, 0,    0>
        0.25      , <+A, 0, +2*B>
        0.50 - Nil, <-A, 0, +2*B>
        0.50      , <-A, 0,   +B>  // or <-A, 0, -B>
        0.50 + Nil, <-A, 0, -2*B>
        0.75      , <+A, 0, -2*B>
        1.00      , <+A, 0,    0>
    }

#declare Spline2 =
    spline {
        linear_spline
        0.00, <+A, 0, +2*B>
        0.25, <-A, 0, +2*B>
        0.50, <-A, 0,    0>
        0.75, <-A, 0, -2*B>
        1.00, <+A, 0, -2*B>
    }

#declare NrOfSteps = 1000;
#declare dS = 1/NrOfSteps;

#declare EllipseSpline =
    spline {
        linear_spline
        #for (I, 0, NrOfSteps)
            #declare S = I*dS;
            #declare p1 = Spline1(S);
            #declare p2 = Spline2(S);
            #declare E = (p1.x + A)*p2.z;
            #declare F = (p2.x - A)*p1.z;
            S, A/(E - F)*<E + F, 0, 2*p1.z*p2.z>
        #end // while
    }

#declare LengthSpline =
    spline {
        linear_spline
        #declare LengthSum = 0;
        #declare pP = EllipseSpline(0);
        #for (I, 0, NrOfSteps)
            #declare S = I*dS;
            #declare pN = EllipseSpline(S);
            #declare Length = vlength(pN - pP);
            #declare LengthSum = LengthSum + Length;
            S, LengthSum*<1, 1>
            #declare pP = pN;
        #end // for
    }

#declare TotalLength = LengthSpline(1).u;

#declare InverseLengthSpline =
    spline {
        linear_spline
        #for (I, 0, NrOfSteps)
            #declare S = I*dS;
            #declare Length = LengthSpline(S).u;
            #declare NL = Length/TotalLength;
            NL, S*<1, 1>
        #end // for
    }

#declare dNL = 1/NrOfSteps;
#declare UniformIntervalsSpline =
    spline {
        linear_spline
        #for (I, 0, NrOfSteps)
            #declare NL = I*dNL;
            #declare S = InverseLengthSpline(NL).u;
            NL, EllipseSpline(S)
        #end // for
    }

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

#declare NrOfCylinders = 40;

#declare Cylinders =
    union {
        #for (I, 1, NrOfCylinders)
            #declare pS = UniformIntervalsSpline(I/NrOfCylinders);
            cylinder {
                -D*y, +D*y, R
                translate pS
            }
        #end // for
    }

object {
    Cylinders
    pigment { color Yellow }
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7

camera {
    location 4*y
    look_at 0*y
    sky z
}

light_source {
    100*y
    color White
}

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7


Post a reply to this message

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