Search in sources :

Example 51 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class AffineTransformWidget method updateInternalValue.

/**
 * Updates the internal representation of the value, updates any result
 * holders, and returns true if the new value differs from the old value.
 */
protected boolean updateInternalValue(Object value) {
    if (!valuesEqual(value, getInternalValue())) {
        maskValueChanges(true);
        if (value == Property.VoidValue) {
            for (LabeledTextField c : myFields) {
                c.setValue(Property.VoidValue);
            }
            myValueIsVoid = true;
        } else {
            RotationMatrix3d R = new RotationMatrix3d();
            Vector3d p = new Vector3d();
            Vector3d scale = new Vector3d(1, 1, 1);
            Vector3d shear = new Vector3d(0, 0, 0);
            if (value instanceof RigidTransform3d) {
                RigidTransform3d newX = (RigidTransform3d) value;
                p.set(newX.p);
                R.set(newX.R);
            // System.out.println ("newT\n" + newX.toString("%10.6f"));
            } else if (value instanceof AffineTransform3d) {
                AffineTransform3d newX = (AffineTransform3d) value;
                p.set(newX.p);
                newX.factorA(R, scale, shear);
            // System.out.println ("newX\n" + newX.toString("%10.6f"));
            } else {
                throw new InternalErrorException("Unknown value type " + value.getClass());
            }
            setTranslation(p);
            setRotation(R.getAxisAngle());
            setScale(scale);
            setShear(shear);
            myValueIsVoid = false;
        }
        maskValueChanges(false);
        return true;
    } else {
        return false;
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) InternalErrorException(maspack.util.InternalErrorException) RotationMatrix3d(maspack.matrix.RotationMatrix3d) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 52 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class Translator3d method intersectRayAndFixture.

private void intersectRayAndFixture(Point3d p, Line ray) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld);
    switch(mySelectedComponent) {
        case X_AXIS:
            {
                double l = xAxis.nearestPoint(p, draggerRay);
                p.y = p.z = 0;
                break;
            }
        case Y_AXIS:
            {
                yAxis.nearestPoint(p, draggerRay);
                p.x = p.z = 0;
                break;
            }
        case Z_AXIS:
            {
                zAxis.nearestPoint(p, draggerRay);
                p.x = p.y = 0;
                break;
            }
        case XY_PLANE:
            {
                draggerRay.intersectPlane(p, xyPlane);
                p.z = 0;
                break;
            }
        case YZ_PLANE:
            {
                draggerRay.intersectPlane(p, yzPlane);
                p.x = 0;
                break;
            }
        case ZX_PLANE:
            {
                draggerRay.intersectPlane(p, zxPlane);
                p.y = 0;
                break;
            }
        default:
            {
                throw new InternalErrorException("unexpected case " + mySelectedComponent);
            }
    }
}
Also used : Line(maspack.matrix.Line) InternalErrorException(maspack.util.InternalErrorException)

Example 53 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class Transrotator3d method findRotation.

/**
 * Given a ray intersecting one of the rotational dragger components, find
 * the intersection point p on the component (in dragger coordinates),
 * along with the corresponding rotation R.
 */
protected void findRotation(RotationMatrix3d R, Point3d p, Line ray) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld0);
    switch(mySelectedComponent) {
        case X_ROTATE:
            {
                draggerRay.intersectPlane(p, yzPlane);
                R.setAxisAngle(xAxis.getDirection(), Math.atan2(p.z, p.y));
                break;
            }
        case Y_ROTATE:
            {
                draggerRay.intersectPlane(p, zxPlane);
                R.setAxisAngle(yAxis.getDirection(), Math.atan2(p.x, p.z));
                break;
            }
        case Z_ROTATE:
            {
                draggerRay.intersectPlane(p, xyPlane);
                R.setAxisAngle(zAxis.getDirection(), Math.atan2(p.y, p.x));
                break;
            }
        default:
            {
                throw new InternalErrorException("unexpected case " + mySelectedComponent);
            }
    }
    double mag = p.norm();
    if (mag != 0) {
        p.scale(myRotatorRelativeSize * mySize / mag);
    }
}
Also used : Line(maspack.matrix.Line) InternalErrorException(maspack.util.InternalErrorException)

Example 54 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class LemkeContactSolver method partitionVariables.

private void partitionVariables(ContactVariable drive) {
    thetaAlpha.clear();
    phiAlphaP.clear();
    phiAlphaX.clear();
    wBeta.clear();
    wAlpha.clear();
    kernGamma = null;
    ksize = 0;
    if (drive == null) {
        wzVar = null;
        z0InKernel = false;
    } else {
        wzVar = drive.isZ() ? (ContactVariable) drive.complement : drive;
        if (wzVar.type == GAMMA) {
            kernGamma = wzVar;
        }
        z0InKernel = true;
        ksize++;
    }
    for (int i = 0; i < numc; i++) {
        ContactVariable theta = zVars[i];
        ContactVariable nu = wVars[i];
        phiXArray[i] = null;
        if (theta.isBasic) {
            thetaAlpha.add(theta);
            wAlpha.add(nu);
            ksize++;
        } else if (nu.isBasic) {
            wBeta.add(nu);
        }
        if (frictionStatus[i] == FRICTION_ACTIVE) {
            ContactVariable lambda = zVars[theta.di + numd];
            ContactVariable gamma = wVars[theta.di + numd];
            for (int j = 0; j < numd; j++) {
                ContactVariable phi = zVars[theta.di + j];
                ContactVariable sigma = wVars[theta.di + j];
                if (phi.isBasic) {
                    if (lambda.isBasic && phiXArray[i] == null) {
                        phiAlphaX.add(phi);
                        phiXArray[i] = phi;
                    } else {
                        phiAlphaP.add(phi);
                        ksize++;
                    }
                    wAlpha.add(sigma);
                // phiCnt[i]++;
                } else if (sigma.isBasic) {
                    wBeta.add(sigma);
                }
            }
            if (lambda.isBasic) {
                wAlpha.add(gamma);
                if (phiXArray[i] == null) {
                    // sanity check
                    if (kernGamma != null) {
                        throw new InternalErrorException("zero col lambda not unique: contacts " + kernGamma.ci + " and " + lambda.ci);
                    }
                    if (wzVar == null || lambda.ci != wzVar.ci || wzVar.type != SIGMA) {
                        throw new InternalErrorException("zero col lambda not associated with sigma, contact" + lambda.ci);
                    }
                    kernGamma = (ContactVariable) lambda.complement;
                }
            } else if (gamma.isBasic) {
                wBeta.add(gamma);
            }
        }
    }
    if (wzVar != null) {
        wAlpha.add(wzVar);
    }
    String caseName = "PRINCIPAL";
    if (wzVar != null) {
        if (wzVar.type == NU) {
            caseName = "NU";
        } else if (wzVar.type == SIGMA && kernGamma == null) {
            caseName = "SIGMA non-zero";
        } else if (wzVar.type == SIGMA) {
            caseName = "SIGMA zero";
        } else if (wzVar.type == GAMMA) {
            caseName = "GAMMA";
        } else {
            throw new InternalErrorException("bogus type: " + wzVar.getName());
        }
    }
    thetaAlpha.close();
    phiAlphaP.close();
    phiAlphaX.close();
    wBeta.close();
    wAlpha.close();
    if (false) {
        System.out.println("ta:" + thetaAlpha.size() + " pa:" + phiAlphaP.size() + " px:" + phiAlphaX.size() + " ksize:" + ksize + " " + caseName);
    }
    if (ksize == 8) {
        printBasis(drive);
    }
}
Also used : InternalErrorException(maspack.util.InternalErrorException)

Example 55 with InternalErrorException

use of maspack.util.InternalErrorException in project artisynth_core by artisynth.

the class Rotator3d method findRotation.

private void findRotation(RotationMatrix3d R, Point3d p, Line ray) {
    Line draggerRay = new Line(ray);
    draggerRay.inverseTransform(myXDraggerToWorld0);
    switch(mySelectedComponent) {
        case X_AXIS:
            {
                draggerRay.intersectPlane(p, yzPlane);
                R.setAxisAngle(xAxis.getDirection(), Math.atan2(p.z, p.y));
                break;
            }
        case Y_AXIS:
            {
                draggerRay.intersectPlane(p, zxPlane);
                R.setAxisAngle(yAxis.getDirection(), Math.atan2(p.x, p.z));
                break;
            }
        case Z_AXIS:
            {
                draggerRay.intersectPlane(p, xyPlane);
                R.setAxisAngle(zAxis.getDirection(), Math.atan2(p.y, p.x));
                break;
            }
        case OUTER_SPHERE:
            {
                break;
            }
        default:
            {
                throw new InternalErrorException("unexpected case " + mySelectedComponent);
            }
    }
    double mag = p.norm();
    if (mag != 0) {
        p.scale(mySize / mag);
    }
}
Also used : Line(maspack.matrix.Line) InternalErrorException(maspack.util.InternalErrorException)

Aggregations

InternalErrorException (maspack.util.InternalErrorException)92 Vector3d (maspack.matrix.Vector3d)9 CompositeProperty (maspack.properties.CompositeProperty)8 Point3d (maspack.matrix.Point3d)7 Property (maspack.properties.Property)7 FemModel3d (artisynth.core.femmodels.FemModel3d)6 Point (artisynth.core.mechmodels.Point)6 ModelComponent (artisynth.core.modelbase.ModelComponent)5 PolygonalMesh (maspack.geometry.PolygonalMesh)5 Line (maspack.matrix.Line)5 RigidTransform3d (maspack.matrix.RigidTransform3d)5 EditingProperty (maspack.properties.EditingProperty)5 BadLocationException (javax.swing.text.BadLocationException)4 RotationMatrix3d (maspack.matrix.RotationMatrix3d)4 RigidBody (artisynth.core.mechmodels.RigidBody)3 RootModel (artisynth.core.workspace.RootModel)3 File (java.io.File)3 IOException (java.io.IOException)3 LinkedList (java.util.LinkedList)3 SelectionManager (artisynth.core.gui.selectionManager.SelectionManager)2