-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomPointGroup.java
More file actions
77 lines (70 loc) · 1.78 KB
/
RandomPointGroup.java
File metadata and controls
77 lines (70 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import edu.rit.util.Random;
import java.util.NoSuchElementException;
/**
* Class RandomPointGroup provides a group of 3-D points at random coordinates.
*
* @author Alan Kaminsky
* @version 10-Oct-2016
*/
public class RandomPointGroup
implements PointGroup
{
private int N;
private double max;
private Random prng;
private int generated;
/**
* Construct a new random point group. The points' coordinates are chosen at
* random in the range -max .. +max.
*
* @param N Number of points.
* @param max Maximum absolute coordinate value.
* @param seed Seed for pseudorandom number generator.
*/
public RandomPointGroup
(int N,
int max,
long seed)
{
this.N = N;
this.max = max;
this.prng = new Random (seed);
}
/**
* Returns the number of points in this group, N.
*/
public int N()
{
return N;
}
/**
* Obtain the next point in this point group. This method must be called
* repeatedly, N times, to obtain all the edges. Each time this method is
* called, it stores, in the fields of object point, the coordinates of the
* next point.
*
* @param point Point object in which to store the coordinates.
*
* @exception NoSuchElementException
* (unchecked exception) Thrown if this method is called more than N
* times.
*/
public void nextPoint
(Point point)
{
if (generated == N)
throw new NoSuchElementException
("RandomPointGroup.nextPoint(): Too many points generated");
point.x = randomCoordinate();
point.y = randomCoordinate();
point.z = randomCoordinate();
++ generated;
}
/**
* Returns a random coordinate.
*/
private double randomCoordinate()
{
return (prng.nextDouble()*2.0 - 1.0)*max;
}
}