use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MeshFactory method createSphericalPolyline.
public static PolylineMesh createSphericalPolyline(double r, int nslices, int nlevels) {
PolylineMesh mesh = new PolylineMesh();
int[] lineIdxs = new int[nlevels - 1];
int vtxIdx = 0;
for (int j = 0; j < nslices; j++) {
double the = 2 * Math.PI * (j / (double) nslices);
double cthe = Math.cos(the);
double sthe = Math.sin(the);
for (int i = 1; i < nlevels; i++) {
double phi = Math.PI / 2 - Math.PI * (i / (double) (nlevels));
double cphi = Math.cos(phi);
double sphi = Math.sin(phi);
mesh.addVertex(new Point3d(r * cphi * cthe, r * cphi * sthe, r * sphi));
lineIdxs[i - 1] = vtxIdx++;
}
mesh.addLine(lineIdxs);
}
return mesh;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MeshFactory method createQuadSphere.
public static PolygonalMesh createQuadSphere(double r, int nslices, int nlevels, double x, double y, double z, boolean addTextureCoords) {
double tol = computeSphericalPointTolerance(r, 2 * Math.PI, Math.PI, nslices, nlevels);
PolygonalMesh mesh = new PolygonalMesh();
VertexMap vtxMap = new VertexMap(tol);
RigidTransform3d XLM = new RigidTransform3d(x, y, z);
addQuadSphericalSection(mesh, r, Math.PI, Math.PI, nslices, nlevels, XLM, vtxMap);
if (addTextureCoords) {
Point3d origin = new Point3d(x, y, z);
computeTextureCoordsForSphere(mesh, origin, r, tol);
}
return mesh;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method findNearestFeature.
/**
* Find the nearest feature on a tet to a point p0. eps is a tolerance
* (in the range [0,1]) used to check the barycentric coordinates
* of p0 to see if it is actually close to a feature. If it
* is not, this method returns null.
*/
TetFeature findNearestFeature(TetDesc desc, Point3d p0Loc, double eps) {
if (myTetBarycentricMats == null) {
createTetBarycentricMats();
}
// convert p0Loc to quad grid coordinates, and the multiply by the
// barycentric conversion matrix to get barycentric coordinates s1, s2,
// s3. s0 is then given by s0 = 1 - s1 - s2 - s2.
Point3d pc = new Point3d();
Vector3d sv = new Vector3d();
transformToQuadCell(pc, p0Loc, desc);
myTetBarycentricMats[desc.myTetId.intValue()].mul(sv, pc);
// code is a bit code describing which coordinates are close to 0
int code = 0;
if (Math.abs(1 - sv.get(0) - sv.get(1) - sv.get(2)) < eps) {
code |= 0x01;
}
if (Math.abs(sv.get(0)) < eps) {
code |= 0x02;
}
if (Math.abs(sv.get(1)) < eps) {
code |= 0x04;
}
if (Math.abs(sv.get(2)) < eps) {
code |= 0x08;
}
int[] nodes = desc.myTetId.getNodes();
switch(code) {
case 0x01:
{
return new TetFace(nodes[1], nodes[3], nodes[2]);
}
case 0x02:
{
return new TetFace(nodes[0], nodes[2], nodes[3]);
}
case 0x04:
{
return new TetFace(nodes[0], nodes[3], nodes[1]);
}
case 0x08:
{
return new TetFace(nodes[0], nodes[1], nodes[2]);
}
case 0x03:
return new TetEdge(nodes[2], nodes[3]);
case 0x05:
return new TetEdge(nodes[1], nodes[3]);
case 0x09:
return new TetEdge(nodes[1], nodes[2]);
case 0x06:
return new TetEdge(nodes[0], nodes[3]);
case 0x0a:
return new TetEdge(nodes[0], nodes[2]);
case 0x0c:
return new TetEdge(nodes[0], nodes[1]);
case 0x0e:
return new TetNode(nodes[0]);
case 0x0d:
return new TetNode(nodes[1]);
case 0x0b:
return new TetNode(nodes[2]);
case 0x07:
return new TetNode(nodes[3]);
default:
{
return null;
}
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method intersectTriangle.
void intersectTriangle(TetPlaneIntersection isect, TetDesc tdesc, Point3d[] vpnts, double[] dist, int i0, int i1, int i2, int i3) {
int[] nodes = tdesc.myTetId.getNodes();
int n0 = nodes[i0];
Point3d p0 = vpnts[i0];
double d0 = dist[i0];
double EPS = 1e-8;
double s1 = d0 / (d0 - dist[i1]);
double s2 = d0 / (d0 - dist[i2]);
double s3 = d0 / (d0 - dist[i3]);
int numsmall = 0;
if (s1 <= EPS) {
numsmall++;
}
if (s2 <= EPS) {
numsmall++;
}
if (s3 <= EPS) {
numsmall++;
}
if (numsmall > 1) {
isect.myNumSides = 0;
}
isect.myP0.combine(1 - s1, p0, s1, vpnts[i1]);
isect.myP1.combine(1 - s2, p0, s2, vpnts[i2]);
isect.myP2.combine(1 - s3, p0, s3, vpnts[i3]);
isect.myNumSides = 3;
isect.myCCW = d0 < 0 ? 1 : -1;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class DistanceGridSurfCalc method getFeatureAdjacentTets.
protected int getFeatureAdjacentTets(TetDesc tdesc, TetFeature feat, Plane plane, HashSet<TetDesc> visited) {
createConnectivityIfNecessary();
Point3d[] vpnts = new Point3d[] { new Point3d(), new Point3d(), new Point3d(), new Point3d() };
if (feat instanceof TetFace) {
TetDesc adjDesc = myFaceTets.get((TetFace) feat);
TetDesc adesc = new TetDesc(adjDesc);
adesc.addOffset(tdesc);
if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
getVertexCoords(vpnts, adesc);
TetPlaneIntersection isect = getIsect(0);
if (intersectTetAndPlane(isect, adesc, vpnts, plane)) {
return 1;
}
}
return 0;
} else {
TetDesc[] adjDescs = null;
if (feat instanceof TetNode) {
adjDescs = myNodeTets.get(((TetNode) feat).getNode());
} else {
// feat instanceof TetEdge
adjDescs = myEdgeTets.get((TetEdge) feat);
}
int numi = 0;
for (int i = 0; i < adjDescs.length; i++) {
TetDesc adesc = new TetDesc(adjDescs[i]);
adesc.addOffset(tdesc);
if (myGrid.inRange(adesc) && (visited == null || !visited.contains(adesc))) {
// different from that of tdesc
if ((feat instanceof TetNode && !adesc.cellEquals(tdesc)) || (feat instanceof TetEdge && !adesc.equals(tdesc))) {
getVertexCoords(vpnts, adesc);
TetPlaneIntersection isect = getIsect(numi);
if (intersectTetAndPlane(isect, adesc, vpnts, plane)) {
numi++;
}
}
}
}
return numi;
}
}
Aggregations