use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class SkinDemo method addMuscle.
public void addMuscle() {
RigidBody upperArm = model.rigidBodies().get("upper");
RigidBody lowerArm = model.rigidBodies().get("lower");
if (upperArm == null || lowerArm == null) {
return;
}
Point3d markerBodyPos = new Point3d(-size.x / 2, 0, (size.z / 2.0) / 1.2);
FrameMarker u = new FrameMarker();
model.addFrameMarker(u, upperArm, markerBodyPos);
u.setName("upperAttachment");
markerBodyPos = new Point3d(size.x / 2, 0, -(size.z / 2.0) / 2);
FrameMarker l = new FrameMarker();
model.addFrameMarker(l, lowerArm, markerBodyPos);
l.setName("lowerAttachment");
Muscle muscle = new Muscle("muscle");
muscle.setPeckMuscleMaterial(20.0, 22.0, 30, 0.2, 0.5, 0.1);
muscle.setFirstPoint(u);
muscle.setSecondPoint(l);
RenderProps rp = new RenderProps(model.getRenderProps());
rp.setLineStyle(Renderer.LineStyle.SPINDLE);
rp.setLineRadius(len / 20);
// rp.setLineSlices(10);
rp.setShading(Renderer.Shading.SMOOTH);
rp.setLineColor(Color.RED);
muscle.setRenderProps(rp);
model.addAxialSpring(muscle);
if (addCompression) {
markerBodyPos = new Point3d(size.x / 2, 0, +size.z / 2.0);
FrameMarker l2 = new FrameMarker();
model.addFrameMarker(l2, lowerArm, markerBodyPos);
l2.setName("lowerAttachmentCompressor");
double len = u.getPosition().distance(l2.getPosition());
AxialSpring s = new AxialSpring(10, 0, 50);
s.setFirstPoint(u);
s.setSecondPoint(l2);
model.addAxialSpring(s);
RenderProps props = new RenderProps();
props.setLineStyle(Renderer.LineStyle.CYLINDER);
props.setLineRadius(0.0);
s.setRenderProps(props);
}
}
use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class FemBeamWithMuscle method build.
public void build(String[] args) throws IOException {
// Create simple FEM beam
super.build(args);
// Add a particle fixed in space
Particle p1 = new Particle(/*mass=*/
0, -length / 2, 0, 2 * width);
mech.addParticle(p1);
p1.setDynamic(false);
RenderProps.setSphericalPoints(p1, 0.02, Color.BLUE);
// Add a marker at the end of the model
FemMarker mkr = createMarker(fem, length / 2 - 0.1, 0, width / 2);
// Create a muscle between the point an marker
Muscle muscle = createMuscle();
muscle.setPoints(p1, mkr);
mech.addAxialSpring(muscle);
}
use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class FemBeamWithMuscle method createMuscle.
// Creates a point-to-point muscle
protected Muscle createMuscle() {
Muscle mus = new Muscle(/*name=*/
null, /*restLength=*/
0);
mus.setMaterial(new SimpleAxialMuscle(/*stiffness=*/
20, /*damping=*/
10, /*maxf=*/
10));
RenderProps.setLineStyle(mus, Renderer.LineStyle.SPINDLE);
RenderProps.setLineColor(mus, Color.RED);
RenderProps.setLineRadius(mus, 0.03);
return mus;
}
use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class MuscleBundle method setMaxForce.
public void setMaxForce(double maxForce) {
for (int i = 0; i < myFibres.size(); i++) {
Muscle mus = myFibres.get(i);
if (mus.getMaterial() instanceof AxialMuscleMaterial) {
AxialMuscleMaterial mat = (AxialMuscleMaterial) mus.getMaterial().clone();
mat.setMaxForce(maxForce);
mus.setMaterial(mat);
}
}
}
use of artisynth.core.mechmodels.Muscle in project artisynth_core by artisynth.
the class MuscleBundle method getNewElementsNearFibres.
/**
* Returns a list of MuscleElementDesc identifying all elements that are (a)
* within a specified distance of the fibres, and (b) not already referenced
* by this bundle.
*/
public LinkedList<MuscleElementDesc> getNewElementsNearFibres(double dist) {
LinkedList<MuscleElementDesc> list = new LinkedList<MuscleElementDesc>();
if (myFibres.size() == 0) {
return list;
}
FemModel3d femMod = getAncestorFem(this);
RenderableComponentList<FemElement3d> elems = femMod.getElements();
Point3d[] elemLocs = new Point3d[elems.size()];
Point3d[] muscleLocs = new Point3d[myFibres.size()];
Vector3d[] muscleDirs = new Vector3d[myFibres.size()];
double[] muscleLens = new double[myFibres.size()];
Point3d pos1 = new Point3d();
Point3d pos2 = new Point3d();
Vector3d dir = new Vector3d();
for (int j = 0; j < elems.size(); j++) {
FemElement3d e = elems.get(j);
elemLocs[j] = new Point3d();
IntegrationPoint3d warpingPnt = e.getWarpingPoint();
warpingPnt.computeRestPosition(elemLocs[j], e.getNodes());
}
for (int i = 0; i < myFibres.size(); i++) {
Muscle fibre = myFibres.get(i);
getRestPosition(pos1, fibre.getFirstPoint());
getRestPosition(pos2, fibre.getSecondPoint());
muscleLocs[i] = new Point3d();
muscleLocs[i].combine(0.5, pos2, 0.5, pos1);
dir.sub(pos2, pos1);
muscleLens[i] = dir.norm();
dir.normalize();
muscleDirs[i] = new Vector3d(dir);
}
int[] nearestFibreIndex = new int[elems.size()];
double[] nearestFibreDistance = new double[elems.size()];
boolean[] bundleHasElement = new boolean[elems.size()];
for (int j = 0; j < elems.size(); j++) {
nearestFibreIndex[j] = -1;
nearestFibreDistance[j] = Double.MAX_VALUE;
}
for (int k = 0; k < myElementDescs.size(); k++) {
FemElement3d e = myElementDescs.get(k).getElement();
bundleHasElement[elems.indexOf(e)] = true;
}
// time critical
for (int i = 0; i < myFibres.size(); i++) {
for (int j = 0; j < elems.size(); j++) {
double d = getFibreDist(elemLocs[j], muscleLocs[i], muscleDirs[i], muscleLens[i]);
if (d < dist && d < nearestFibreDistance[j]) {
nearestFibreDistance[j] = d;
nearestFibreIndex[j] = i;
}
}
}
for (int j = 0; j < elems.size(); j++) {
if (!bundleHasElement[j] && nearestFibreIndex[j] != -1) {
MuscleElementDesc desc = new MuscleElementDesc();
desc.setElement(elems.get(j));
desc.setDirection(muscleDirs[nearestFibreIndex[j]]);
list.add(desc);
}
}
return list;
}
Aggregations