use of artisynth.core.femmodels.FemNode3d in project artisynth_core by artisynth.
the class TransverseIsotropy method build.
@Override
public void build(String[] args) throws IOException {
super.build(args);
MechModel mech = new MechModel("mech");
addModel(mech);
double h = 0.1;
double r = 0.005;
RigidBody rb = RigidBody.createBox("box", 2 * r, 2 * r, 2 * r, 100, true);
mech.addRigidBody(rb);
rb.transformGeometry(new RigidTransform3d(new Vector3d(0, 0, -h / 2 - r), AxisAngle.IDENTITY));
FemModel3d fem = FemFactory.createCylinder(null, h, r, 24, 40, 4);
fem.setDensity(1000);
mech.addModel(fem);
TransverseLinearMaterial mat = new TransverseLinearMaterial();
mat.setYoungsModulus(50000, 50000);
mat.setPoissonsRatio(0.45, 0.45);
double G = 50000 / (2 * (1 + 0.45));
mat.setShearModulus(G);
fem.setMaterial(mat);
fem.setName("fem");
fem.setSurfaceRendering(SurfaceRender.Shaded);
RenderProps.setFaceColor(fem, Color.ORANGE);
RenderProps.setVisible(fem.getElements(), false);
double eps = 1e-10;
for (FemNode3d node : fem.getNodes()) {
if (node.getPosition().z > h / 2 - eps) {
node.setDynamic(false);
} else if (node.getPosition().z < -h / 2 + eps) {
PointAttachment pa = rb.createPointAttachment(node);
mech.addAttachment(pa);
}
}
}
use of artisynth.core.femmodels.FemNode3d in project artisynth_core by artisynth.
the class Fem3dBlock method build.
public void build(String type, int nz, int nxy, int options) {
FemModel3d femMod = new FemModel3d("fem");
femMod.setDensity(myDensity);
if (type.equals("tet")) {
FemFactory.createTetGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
} else if (type.equals("hex")) {
FemFactory.createHexGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
} else if (type.equals("quadtet")) {
FemFactory.createQuadtetGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
} else if (type.equals("quadhex")) {
FemFactory.createQuadhexGrid(femMod, 0.6, 0.2, 0.2, nz, nxy, nxy);
} else {
throw new UnsupportedOperationException("Unsupported element type " + type);
}
femMod.setBounds(new Point3d(-0.6, 0, 0), new Point3d(0.6, 0, 0));
femMod.setLinearMaterial(200000, 0.4, true);
femMod.setStiffnessDamping(0.002);
Renderable elements = femMod.getElements();
RenderProps.setLineWidth(elements, 2);
RenderProps.setLineColor(elements, Color.BLUE);
Renderable nodes = femMod.getNodes();
RenderProps.setPointStyle(nodes, Renderer.PointStyle.SPHERE);
RenderProps.setPointRadius(nodes, 0.01);
RenderProps.setPointColor(nodes, new Color(153, 0, 204));
// fix the leftmost nodes
LinkedList<FemNode3d> leftNodes = getLeftNodes(femMod);
LinkedList<FemNode3d> rightNodes = getRightNodes(femMod);
myAttachNodes = rightNodes.toArray(new FemNode3d[0]);
double wx, wy, wz;
double mass;
RigidTransform3d X = new RigidTransform3d();
PolygonalMesh mesh;
MechModel mechMod = new MechModel("mech");
// mechMod.setPrintState ("%10.5f");
wx = 0.1;
wy = 0.3;
wz = 0.3;
RigidBody leftBody = new RigidBody("leftBody");
mass = wx * wy * wz * myDensity;
leftBody.setInertia(SpatialInertia.createBoxInertia(mass, wx, wy, wz));
mesh = MeshFactory.createBox(wx, wy, wz);
// mesh.setRenderMaterial (Material.createSpecial (Material.GRAY));
leftBody.setMesh(mesh, /* fileName= */
null);
X.R.setIdentity();
X.p.set(-0.35, 0, 0);
leftBody.setPose(X);
leftBody.setDynamic(true);
mechMod.addRigidBody(leftBody);
RenderProps.setPointStyle(mechMod, Renderer.PointStyle.SPHERE);
RigidTransform3d TCW = new RigidTransform3d();
RigidTransform3d TCA = new RigidTransform3d();
TCA.p.set(0, 0, wz / 2);
TCA.R.mulAxisAngle(1, 0, 0, Math.PI / 2);
TCW.mul(X, TCA);
RevoluteJoint joint = new RevoluteJoint(leftBody, TCA, TCW);
RenderProps.setCylindricalLines(joint, 0.01, Color.BLUE);
joint.setAxisLength(0.5);
mechMod.addBodyConnector(joint);
// right box
RigidBody rightBody = new RigidBody("rightBody");
rightBody.setInertia(SpatialInertia.createBoxInertia(mass, wx, wy, wz));
mesh = MeshFactory.createBox(wx, wy, wz);
// mesh.setRenderMaterial (Material.createSpecial (Material.GRAY));
rightBody.setMesh(mesh, /* fileName= */
null);
X.p.set(0.35, 0, 0);
rightBody.setPose(X);
rightBody.setDynamic(true);
mechMod.addRigidBody(rightBody);
mechMod.addModel(femMod);
for (FemNode3d n : leftNodes) {
mechMod.attachPoint(n, leftBody);
}
// femMod.setProfile (true);
mechMod.setIntegrator(Integrator.BackwardEuler);
setConnected(true);
addModel(mechMod);
// mechMod.setProfiling (true);
// int numWays = 10;
// double res = 0.1;
// for (int i = 0; i < numWays; i++) {
// addWayPoint (new WayPoint (TimeBase.secondsToTicks ((i + 1) * res)));
// }
// addWayPoint (new WayPoint (TimeBase.secondsToTicks (5)));
// addBreakPoint(5);
// setupOutputProbes();
addControlPanel(mechMod, femMod);
}
use of artisynth.core.femmodels.FemNode3d in project artisynth_core by artisynth.
the class FemMuscleArm method addFemMuscle.
public void addFemMuscle(Point3d upper, Point3d lower) throws IOException {
upperArm = model.rigidBodies().get("upper");
RigidBody lowerArm = model.rigidBodies().get("lower");
if (upperArm == null || lowerArm == null) {
return;
}
muscle = new PointToPointMuscle("muscle", 1.0, 0.85, "muscle", true);
model.addModel(muscle);
RigidTransform3d X = new RigidTransform3d();
// Point3d upper = new Point3d(2.4, 0, 20), lower = new Point3d(3, 0, -7);
FemNode3d first = muscle.getFirstNode(), last = muscle.getLastNode();
double scale = (upper.distance(lower) / first.getPosition().distance(last.getPosition()));
System.out.println(scale);
AffineTransform3d scaling = new AffineTransform3d();
scaling.setIdentity();
scaling.applyScaling(scale, scale, scale);
// muscle.transformGeometry(scaling);
Vector3d translate = new Vector3d();
translate.sub(upper, first.getPosition());
muscle.transformGeometry(new RigidTransform3d(translate, new AxisAngle()));
Vector3d offfem = new Vector3d(), offtarget = new Vector3d();
offfem.sub(last.getPosition(), first.getPosition());
offtarget.sub(lower, upper);
double angle = offfem.angle(offtarget);
offfem.cross(offtarget);
muscle.transformGeometry(new RigidTransform3d(new Vector3d(-upper.x, -upper.y, -upper.z), new AxisAngle()));
muscle.transformGeometry(new RigidTransform3d(upper, new AxisAngle(offfem, angle)));
muscle.getFirstNode().setDynamic(false);
// ant.getFirstNode().setPosition(new Point3d(2.381, 0.000, 20));
// model.AttachPoint(ant.getFirstNode(),upperArm,new Point3d(-size.x,0,-(size.z/2.0)/1.2));
model.attachPoint(muscle.getLastNode(), lowerArm);
muscle.setMaxForce(300000);
muscle.setExcitation(0.0);
RenderProps rp = new RenderProps(model.getRenderProps());
rp.setFaceColor(Color.RED);
rp.setLineStyle(Renderer.LineStyle.LINE);
rp.setPointStyle(Renderer.PointStyle.POINT);
rp.setShading(Renderer.Shading.SMOOTH);
rp.setLineColor(Color.WHITE);
muscle.setRenderProps(rp);
muscle.setSurfaceRendering(SurfaceRender.Shaded);
}
use of artisynth.core.femmodels.FemNode3d in project artisynth_core by artisynth.
the class FemMuscleDemo method findNearestNode.
FemNode3d findNearestNode(Point3d pnt) {
FemNode3d node = null;
double mind = Double.MAX_VALUE;
for (FemNode3d n : tissue.getNodes()) {
double d = n.distance(pnt);
if (d < mind) {
mind = d;
node = n;
}
}
return node;
}
use of artisynth.core.femmodels.FemNode3d in project artisynth_core by artisynth.
the class FemSkinDemo method getLeftNodes.
LinkedList<FemNode3d> getLeftNodes(FemModel3d femMod) {
LinkedList<FemNode3d> nodes = new LinkedList<FemNode3d>();
double minx = Double.POSITIVE_INFINITY;
for (FemNode3d n : femMod.getNodes()) {
if (n.getPosition().x < minx) {
minx = n.getPosition().x;
}
}
for (FemNode3d n : femMod.getNodes()) {
if (n.getPosition().x < minx + EPS) {
nodes.add(n);
}
}
return nodes;
}
Aggregations