static boolean getNormal(Point3f p1, Point3f p2, Point3f p3, Vector3f normal) { Vector3f v1 = new Vector3f(); Vector3f v2 = new Vector3f(); // Must compute normal v1.sub(p2, p1); v2.sub(p2, p3); normal.cross(v1, v2); normal.negate(); float length = normal.length(); if (length > 0) { length = 1 / length; normal.x *= length; normal.y *= length; normal.z *= length; return true; } return false; }
private static Point3f intersect(final Point3f p1, final Point3f p2, final Vector3f n, final Point3f p3) { // http://paulbourke.net/geometry/planeline/ final Vector3f v1 = new Vector3f(); v1.sub(p3, p1); final Vector3f v2 = new Vector3f(); v2.sub(p2, p1); final float u = (n.dot(v1)) / (n.dot(v2)); final Point3f res = new Point3f(); res.scaleAdd(u, v2, p1); return res; } }
public void getFaceNormal(final int fIdx, final Vector3f ret) { final int f1 = getFace(3 * fIdx); final int f2 = getFace(3 * fIdx + 1); final int f3 = getFace(3 * fIdx + 2); final Vertex v1 = getVertex(f1); final Vertex v2 = getVertex(f2); final Vertex v3 = getVertex(f3); tmpv1.sub(v2, v1); tmpv2.sub(v3, v1); ret.cross(tmpv1, tmpv2); }
a.sub(coordinates[coordInds[t + 2]], coordinates[coordInds[t + 1]]); b.sub(coordinates[coordInds[t + 0]], coordinates[coordInds[t + 1]]); facetNorms[t / 3] = new Vector3f(); facetNorms[t / 3].cross(a, b); a.sub(coordinates[coordInds[t + 2]], coordinates[coordInds[t + 0]]); b.sub(coordinates[coordInds[t + 5]], coordinates[coordInds[t + 1]]); facetNorms[t / 3] = new Vector3f(); facetNorms[t / 3].cross(a, b);
public Vector3f[] getNormals() { final Vector3f[] normals = new Vector3f[nVertices]; for (int i = 0; i < nVertices; i++) normals[i] = new Vector3f(); final Vector3f v1 = new Vector3f(), v2 = new Vector3f(); for (int i = 0; i < nFaces; i += 3) { final int f1 = faces[i]; final int f2 = faces[i + 1]; final int f3 = faces[i + 2]; v1.sub(vertices[f2], vertices[f1]); v2.sub(vertices[f3], vertices[f1]); v1.cross(v1, v2); normals[f1].add(v1); normals[f2].add(v1); normals[f3].add(v1); } for (int i = 0; i < nVertices; i++) normals[i].normalize(); return normals; }
final Point3f p = new Point3f(); final Vector3f dir = new Vector3f(); dir.sub(end, start); dir.normalize(); final float fx = first * dir.x;