Commit 9d66b9a1 authored by Louis  Jimenez-Hernandez's avatar Louis Jimenez-Hernandez
Browse files

Update readFile.java

parent b49b973a
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ public class readFile {
    public static Map<VertexKey,Integer> vertexToIndex = new HashMap<>();
    public static Map<Integer, VertexKey> indexToVertex = new HashMap<>();

    public static float[] vertices;

    private static ArrayList<Integer> faces = new ArrayList<>();

    public static AdjacencyMatrix adjMatrix;
@@ -228,8 +230,24 @@ public class readFile {
     */
    private static String makeLine(Random random) {
        return String.format("[%f,%f,%f] [%f,%f,%f] [%f,%f,%f]",
                random.nextFloat() * 30, random.nextFloat() * 30, random.nextFloat() * 30,
                random.nextFloat() * 30, random.nextFloat() * 30, random.nextFloat() * 30,
                random.nextFloat() * 30, random.nextFloat() * 30, random.nextFloat() * 30);
                vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3],
                vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3],
                vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3], vertices[random.nextInt(vertices.length / 3) * 3]);
    }

    public static void generateRandomVertices(int numVertices) {
        float range = 30;
        Random random = new Random();
        vertices = new float[numVertices * 3];
        for (int i = 0; i < numVertices * 3; i += 3) {
            float x = (random.nextFloat() * range);
            float y = (random.nextFloat() * range);
            float z = (random.nextFloat() * range);

            // Ensures the value stays within range
            vertices[i] = Math.max(0, Math.min(range, x));
            vertices[i + 1] = Math.max(0, Math.min(range, y));
            vertices[i + 2] = Math.max(0, Math.min(range, z));
        }
    }
}