use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MultiSpringTest method addMixedUpSprings.
protected void addMixedUpSprings(MechModel mech) {
Particle p = new Particle(1, new Point3d(0, 0, 0.1));
mech.addParticle(p);
Particle lastp = p;
for (int i = 0; i < 20; ++i) {
p = new Particle(1, new Point3d((i + 1) * 0.1, 2 * (i % 2 - 0.5) * 0.1, 0.1));
mech.addParticle(p);
AxialSpring ax = new AxialSpring("spring mixed " + i);
if (i % 2 == 0) {
ax.setPoints(lastp, p);
} else {
ax.setPoints(p, lastp);
}
mech.addAxialSpring(ax);
lastp = p;
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MultiSpringTest method addSeparatedSprings.
protected void addSeparatedSprings(MechModel mech) {
for (int i = 0; i < 10; ++i) {
Particle p1 = new Particle(1, new Point3d((2 * i) * 0.1, 2 * (i % 2 - 0.5) * 0.1, -0.1));
Particle p2 = new Particle(1, new Point3d((2 * i + 1) * 0.1, -2 * (i % 2 - 0.5) * 0.1, -0.1));
mech.addParticle(p1);
mech.addParticle(p2);
AxialSpring ax = new AxialSpring("spring detached " + i);
if (i % 2 == 0) {
ax.setPoints(p1, p2);
} else {
ax.setPoints(p2, p1);
}
mech.addAxialSpring(ax);
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MultiSpringTest method addSprings.
protected void addSprings(MechModel mech) {
Particle p = new Particle(1, new Point3d(0, 0, 0));
mech.addParticle(p);
Particle lastp = p;
for (int i = 0; i < 20; ++i) {
p = new Particle(1, new Point3d((i + 1) * 0.1, 2 * (i % 2 - 0.5) * 0.1, 0));
mech.addParticle(p);
AxialSpring ax = new AxialSpring("spring " + i);
ax.setPoints(lastp, p);
mech.addAxialSpring(ax);
lastp = p;
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class SDGridTest method build.
@Override
public void build(String[] args) throws IOException {
super.build(args);
PolygonalMesh mesh = new PolygonalMesh();
Vertex3d[] v = new Vertex3d[9 * 2 + 8];
Face[] f = new Face[8 * 6];
int idx = 0;
int fidx = 0;
double c = 64;
v[idx++] = mesh.addVertex(-c, -c, -c);
v[idx++] = mesh.addVertex(-c, -c, 0);
v[idx++] = mesh.addVertex(-c, -c, c);
v[idx++] = mesh.addVertex(-c, 0, -c);
v[idx++] = mesh.addVertex(-c, 0, 0);
v[idx++] = mesh.addVertex(-c, 0, c);
v[idx++] = mesh.addVertex(-c, c, -c);
v[idx++] = mesh.addVertex(-c, c, 0);
v[idx++] = mesh.addVertex(-c, c, c);
// left
f[fidx++] = mesh.addFace(v[0], v[1], v[4]);
f[fidx++] = mesh.addFace(v[1], v[2], v[4]);
f[fidx++] = mesh.addFace(v[2], v[5], v[4]);
f[fidx++] = mesh.addFace(v[5], v[8], v[4]);
f[fidx++] = mesh.addFace(v[8], v[7], v[4]);
f[fidx++] = mesh.addFace(v[7], v[6], v[4]);
f[fidx++] = mesh.addFace(v[6], v[3], v[4]);
f[fidx++] = mesh.addFace(v[3], v[0], v[4]);
v[idx++] = mesh.addVertex(0, -c, -c);
v[idx++] = mesh.addVertex(0, -c, 0);
v[idx++] = mesh.addVertex(0, -c, c);
v[idx++] = mesh.addVertex(0, 0, -c);
// test.addVertex( 0, 0, 0);
v[idx++] = mesh.addVertex(0, 0, c);
v[idx++] = mesh.addVertex(0, c, -c);
v[idx++] = mesh.addVertex(0, c, 0);
v[idx++] = mesh.addVertex(0, c, c);
// back
f[fidx++] = mesh.addFace(v[0], v[9], v[10]);
f[fidx++] = mesh.addFace(v[1], v[0], v[10]);
f[fidx++] = mesh.addFace(v[2], v[1], v[10]);
f[fidx++] = mesh.addFace(v[11], v[2], v[10]);
// top
f[fidx++] = mesh.addFace(v[2], v[11], v[13]);
f[fidx++] = mesh.addFace(v[5], v[2], v[13]);
f[fidx++] = mesh.addFace(v[8], v[5], v[13]);
f[fidx++] = mesh.addFace(v[16], v[8], v[13]);
// front
f[fidx++] = mesh.addFace(v[8], v[16], v[15]);
f[fidx++] = mesh.addFace(v[7], v[8], v[15]);
f[fidx++] = mesh.addFace(v[6], v[7], v[15]);
f[fidx++] = mesh.addFace(v[14], v[6], v[15]);
// bottom
f[fidx++] = mesh.addFace(v[3], v[6], v[12]);
f[fidx++] = mesh.addFace(v[6], v[14], v[12]);
f[fidx++] = mesh.addFace(v[0], v[3], v[12]);
f[fidx++] = mesh.addFace(v[9], v[0], v[12]);
v[idx++] = mesh.addVertex(c, -c, -c);
v[idx++] = mesh.addVertex(c, -c, 0);
v[idx++] = mesh.addVertex(c, -c, c);
v[idx++] = mesh.addVertex(c, 0, -c);
v[idx++] = mesh.addVertex(c, 0, 0);
v[idx++] = mesh.addVertex(c, 0, c);
v[idx++] = mesh.addVertex(c, c, -c);
v[idx++] = mesh.addVertex(c, c, 0);
v[idx++] = mesh.addVertex(c, c, c);
// bottom
f[fidx++] = mesh.addFace(v[17], v[9], v[12]);
f[fidx++] = mesh.addFace(v[20], v[17], v[12]);
f[fidx++] = mesh.addFace(v[23], v[20], v[12]);
f[fidx++] = mesh.addFace(v[14], v[23], v[12]);
f[fidx++] = mesh.addFace(v[9], v[17], v[10]);
f[fidx++] = mesh.addFace(v[17], v[18], v[10]);
f[fidx++] = mesh.addFace(v[18], v[19], v[10]);
f[fidx++] = mesh.addFace(v[19], v[11], v[10]);
f[fidx++] = mesh.addFace(v[11], v[19], v[13]);
f[fidx++] = mesh.addFace(v[19], v[22], v[13]);
f[fidx++] = mesh.addFace(v[22], v[25], v[13]);
f[fidx++] = mesh.addFace(v[25], v[16], v[13]);
f[fidx++] = mesh.addFace(v[16], v[25], v[15]);
f[fidx++] = mesh.addFace(v[25], v[24], v[15]);
f[fidx++] = mesh.addFace(v[24], v[23], v[15]);
f[fidx++] = mesh.addFace(v[23], v[14], v[15]);
f[fidx++] = mesh.addFace(v[25], v[22], v[21]);
f[fidx++] = mesh.addFace(v[22], v[19], v[21]);
f[fidx++] = mesh.addFace(v[19], v[18], v[21]);
f[fidx++] = mesh.addFace(v[18], v[17], v[21]);
f[fidx++] = mesh.addFace(v[17], v[20], v[21]);
f[fidx++] = mesh.addFace(v[20], v[23], v[21]);
f[fidx++] = mesh.addFace(v[23], v[24], v[21]);
f[fidx++] = mesh.addFace(v[24], v[25], v[21]);
// Move in some corner(s)
v[0].setPosition(new Point3d(0, 0, 0));
// v[25].setPosition(new Point3d(0,0,0));
int divisions = 3;
mesh = MeshFactory.subdivide(mesh, divisions);
// randomize vertex order and re-number (to test different chiralities)
ArrayList<Vertex3d> vertices = mesh.getVertices();
Collections.shuffle(vertices);
for (int i = 0; i < vertices.size(); ++i) {
vertices.get(i).setIndex(i);
}
FixedMeshBody fm = new FixedMeshBody("cube", mesh);
RenderProps.setFaceStyle(fm, FaceStyle.FRONT_AND_BACK);
addRenderable(fm);
int cells = 1 << (divisions + 2);
double margin = 1.0 / cells;
cells += 2;
sdgrid = new DistanceGrid(mesh.getFaces(), margin, cells, /*signed=*/
true);
// test a bunch of inside points
Vector3d norm = new Vector3d();
double dx = 2 * c / ((1 << (divisions + 1)));
for (double x = -c + dx; x < c; x += dx) {
for (double y = -c + dx; y < c; y += dx) {
for (double z = -c + dx; z < c; z += dx) {
double d = sdgrid.getLocalDistanceAndNormal(norm, x, y, z);
// check bottom corner
if ((x < 0 && y < 0 && z < 0)) {
// ||(x > 0 && y > 0 && z > 0)) {
if (d < 0) {
System.err.println("Point (" + x + "," + y + "," + z + ") incorrectly labelled as inside");
}
} else {
if (d > 0) {
System.err.println("Point (" + x + "," + y + "," + z + ") incorrectly labelled as outside");
}
}
}
}
}
RenderProps.setDrawEdges(fm, true);
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class SurfaceMeshCollider method getNearestPoint.
public double getNearestPoint(Point3d nearest, Face f, Point3d p) {
Point3d p0, p1, p2;
p0 = f.getVertex(0).getWorldPoint();
p1 = f.getVertex(1).getWorldPoint();
p2 = f.getVertex(2).getWorldPoint();
return faceIntersector.nearestpoint(p0, p1, p2, p, nearest, null);
}
Aggregations