use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class ArticulatedDemo method addBox.
private RigidBody addBox(MechModel mechMod, double mass, double wx, double wy, double wz, double px, double py, double pz) {
RigidBody box = new RigidBody(null);
box.setInertia(SpatialInertia.createBoxInertia(mass, wx, wy, wz));
box.setMesh(MeshFactory.createBox(wx, wy, wz), null);
RigidTransform3d XBoxToWorld = new RigidTransform3d();
XBoxToWorld.p.set(px, py, pz);
box.setPose(XBoxToWorld);
mechMod.addRigidBody(box);
return box;
}
use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class ArticulatedDemo method create3LinkLoop.
void create3LinkLoop(MechModel mech) {
RigidBody box = addBox(mech, /* mass= */
10, 20, 10, 2, 0, 0, 10);
box.setDynamic(false);
Point3d base0 = new Point3d(-5, 0, 9);
Point3d tip0 = new Point3d(-8, 0, 0);
Point3d base1 = new Point3d(5, 0, 9);
Point3d tip1 = new Point3d(2, -2, 0);
double radius = 1.0;
RigidBody link0 = addSphericalLinkage(mech, radius, ground, base0, null, tip0);
RigidBody link1 = addSphericalLinkage(mech, radius, ground, base1, null, tip1);
RigidBody link2 = addSphericalLinkage(mech, radius, link0, tip0, link1, tip1);
}
use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class ArticulatedDemo method addSphericalLinkage.
private RigidBody addSphericalLinkage(MechModel mechMod, double radius, RigidBody body0, Point3d pnt0, RigidBody body1, Point3d pnt1) {
// set up the position of the link
Vector3d u = new Vector3d();
u.sub(pnt1, pnt0);
double len = u.norm();
u.scale(1 / len);
RigidTransform3d XLinkToWorld = new RigidTransform3d();
XLinkToWorld.p.scaledAdd(0.5 * len, u, pnt0);
XLinkToWorld.R.setZDirection(u);
// create the link
PolygonalMesh mesh = MeshFactory.createRoundedCylinder(radius, len, /*nslices=*/
12, /*nsegs=*/
1, /*flatBottom=*/
false);
SpatialInertia inertia = SpatialInertia.createBoxInertia(/* mass= */
10, radius, radius, len);
RigidBody link = new RigidBody(null);
link.setInertia(inertia);
link.setMesh(mesh, null);
link.setPose(XLinkToWorld);
mechMod.addRigidBody(link);
// create the spherical joint(s)
RigidTransform3d TCW = new RigidTransform3d();
RigidTransform3d TCA = new RigidTransform3d();
if (body0 != null) {
TCA.setIdentity();
TCA.p.set(0, 0, -len / 2);
TCW.mul(XLinkToWorld, TCA);
SphericalJoint joint0;
if (body0 == ground) {
joint0 = new SphericalJoint(link, TCA, TCW);
} else {
RigidTransform3d TCB = new RigidTransform3d();
TCB.mulInverseLeft(body0.getPose(), TCW);
joint0 = new SphericalJoint(link, TCA, body0, TCB);
}
mechMod.addBodyConnector(joint0);
}
if (body1 != null) {
TCA.setIdentity();
TCA.p.set(0, 0, len / 2);
TCW.mul(XLinkToWorld, TCA);
SphericalJoint joint1;
if (body1 == ground) {
joint1 = new SphericalJoint(link, TCA, TCW);
} else {
RigidTransform3d TCB = new RigidTransform3d();
TCB.mulInverseLeft(body1.getPose(), TCW);
joint1 = new SphericalJoint(link, TCA, body1, TCB);
}
mechMod.addBodyConnector(joint1);
}
if (usePlanarContacts) {
// set up a unilateral constraint at the tip
TCW.setIdentity();
TCW.p.set(0, 0, zPlane);
Point3d pCA = new Point3d(0, 0, len / 2);
PlanarConnector contact = new PlanarConnector(link, pCA, TCW);
contact.setUnilateral(true);
contact.setPlaneSize(20);
mechMod.addBodyConnector(contact);
}
return link;
}
use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class ArticulatedFem method makeBox.
private RigidBody makeBox() {
RigidBody box = new RigidBody();
box.setInertia(SpatialInertia.createBoxInertia(boxMass, boxLength, boxHeight, boxHeight));
box.setMesh(MeshFactory.createBox(boxLength, boxHeight, boxHeight), null);
return box;
}
use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.
the class SimpleCollide method createAndAddControlPanel.
ControlPanel createAndAddControlPanel(String name, ModelComponent comp) {
ControlPanel panel = new ControlPanel(name);
if (comp instanceof FemModel3d) {
panel.addWidget(comp, "material");
panel.addWidget(comp, "density");
panel.addWidget(comp, "incompressible");
panel.addWidget(comp, "volume");
} else if (comp instanceof RigidBody) {
panel.addWidget(comp, "position");
panel.addWidget(comp, "orientation");
} else {
throw new InternalErrorException("No control panel code for components of type " + comp.getClass());
}
ControlPanel existingPanel = getControlPanels().get(name);
if (existingPanel != null) {
int idx = getControlPanels().indexOf(existingPanel);
removeControlPanel(existingPanel);
existingPanel.dispose();
addControlPanel(panel, idx);
Main.getMain().arrangeControlPanels(this);
} else {
addControlPanel(panel);
}
return panel;
}
Aggregations