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

一曲冷凌霜 提交于 2019-12-13 03:43:49

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10286555/having-an-array-of-points-that-form-a-circle-how-to-randomize-one-coordinate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!