Search code examples
math3dgeometrypseudocode

Having an array of points that form a circle how to randomize one coordinate?


We have an array or points (double's X, Y, Z) they form a circle, starting from default rotation angles Xa, Ya, Za. We want to extend each point in our circle by one axes (say Z) on some random variable. How to do such thing in pseudocode?


Solution

  • Do you mean something like this (pseudocode):

    void randomize(Point[] points, Axis axis, double scale) {
        RandomNumberGenerator rng = new RandomNumberGenerator();
        for (Point point : points) {
            point[axis] += scale * rng.nextRandom();
        }
    }
    

    If you need to displace points along some direction that is not an axis, you'd modify the above to compute the displacement vector components and add each component to the corresponding point coordinate.