use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class NURBSCurveBase method bracket.
protected boolean bracket(double[] u, double[] sv, Point3d pnt, double smin, double smax) {
Point3d pntu = new Point3d();
boolean bracketted = false;
double s0 = smin;
double s1 = (smin + smax) / 2.0;
double s2 = smax;
eval(pntu, smin);
double uinit = pntu.distance(pnt);
eval(pntu, smax);
double ufinal = pntu.distance(pnt);
double u1 = uinit;
if (ufinal >= uinit) {
while (s2 - s0 > U_SEARCH_TOL) {
s1 = (s2 + s0) / 2;
eval(pntu, s1);
u1 = pntu.distance(pnt);
if (u1 < uinit) {
bracketted = true;
break;
} else {
s2 = s1;
}
}
} else {
while (s2 - s0 > U_SEARCH_TOL) {
s1 = (s2 + s0) / 2;
eval(pntu, s1);
u1 = pntu.distance(pnt);
if (u1 < ufinal) {
bracketted = true;
break;
} else if (u1 == ufinal) {
s2 = s1;
} else {
s0 = s1;
}
}
}
u[0] = u1;
sv[0] = s0;
sv[1] = s1;
sv[2] = s2;
return (bracketted);
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class HalfEdge method nearestPoint.
//
// @Override
// public void nearestPoint(Point3d nearest, Point3d pnt) {
// Point3d p0 = tail.getWorldPoint();
// Point3d p1 = head.getWorldPoint();
//
// double s = projectionParameter(p0, p1, pnt);
// if (s >= 1.0) {
// nearest.set(p0);
// }
// else if (s <= 0) {
// nearest.set(p1);
// }
// else {
// nearest.combine (1-s, p0, s, p1);
// }
// }
@Override
public void nearestPoint(Point3d nearest, Point3d pnt) {
Point3d p0 = tail.getWorldPoint();
Point3d p1 = head.getWorldPoint();
double ux = p1.x - p0.x;
double uy = p1.y - p0.y;
double uz = p1.z - p0.z;
double dx, dy, dz;
dx = pnt.x - p1.x;
dy = pnt.y - p1.y;
dz = pnt.z - p1.z;
double dot = dx * ux + dy * uy + dz * uz;
if (dot >= 0) {
nearest.set(p1);
}
dx = pnt.x - p0.x;
dy = pnt.y - p0.y;
dz = pnt.z - p0.z;
dot = dx * ux + dy * uy + dz * uz;
if (dot <= 0) {
nearest.set(p0);
} else {
double umagSqr = ux * ux + uy * uy + uz * uz;
double s = dot / umagSqr;
pnt.interpolate(p0, s, p1);
}
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class HalfEdge method addAngleWeightedNormal.
// /**
// * Computes the dot product between a vector v1 and a unit vector in the
// * direction of this half-edge.
// *
// * @param v1
// * vector to dot with unit vector
// * @return dot product
// */
// public double dot (Vector3d v1) {
// if (!uOppositeP) {
// return u.dot (v1);
// }
// else {
// return -u.dot (v1);
// }
// }
// /**
// * Computes the dot product between a specified vector and a unit vector in
// * the direction of this half-edge.
// *
// * @param x
// * first coordinate of the specified vector
// * @param y
// * second coordinate of the specified vector
// * @param z
// * third coordinate of the specified vector
// * @return dot product
// */
// public double dot (double x, double y, double z) {
// double prod = u.x * x + u.y * y + u.z * z;
// if (!uOppositeP) {
// return prod;
// }
// else {
// return -prod;
// }
// }
// /**
// * Computes the cross product the unit vector in the direction of
// * this half-edge with the unit vector in the direction of another
// * half-egde, and adds the result to <code>res</code>.
// *
// * @param res
// * Result is added to this vector
// * @param he
// * Half-edge to compute cross product with
// */
// public void crossAdd (Vector3d res, HalfEdge he) {
// Vector3d u2 = he.u;
// if (uOppositeP != he.uOppositeP) {
// // negate the result
// res.x += u2.y*u.z - u2.z*u.y;
// res.y += u2.z*u.x - u2.x*u.z;
// res.z += u2.x*u.y - u2.y*u.x;
// }
// else {
// res.x += u.y*u2.z - u.z*u2.y;
// res.y += u.z*u2.x - u.x*u2.z;
// res.z += u.x*u2.y - u.y*u2.x;
// }
// }
// /**
// * Computes the cross product the unit vector in the direction of
// * this half-edge with the unit vector in the direction of another
// * half-egde, and places the result in <code>res</code>.
// *
// * @param res
// * Result is placed in this vector
// * @param he
// * Half-edge to compute cross product with
// */
// public void cross (Vector3d res, HalfEdge he) {
// Vector3d u2 = he.u;
// if (uOppositeP != he.uOppositeP) {
// // negate the result
// res.x = u2.y*u.z - u2.z*u.y;
// res.y = u2.z*u.x - u2.x*u.z;
// res.z = u2.x*u.y - u2.y*u.x;
// }
// else {
// res.x = u.y*u2.z - u.z*u2.y;
// res.y = u.z*u2.x - u.x*u2.z;
// res.z = u.x*u2.y - u.y*u2.x;
// }
// }
public void addAngleWeightedNormal(Vector3d res, HalfEdge he) {
Point3d p0 = tail.pnt;
Point3d p1 = head.pnt;
Point3d p2 = he.head.pnt;
double u1x = p1.x - p0.x;
double u1y = p1.y - p0.y;
double u1z = p1.z - p0.z;
double mag1 = Math.sqrt(u1x * u1x + u1y * u1y + u1z * u1z);
u1x /= mag1;
u1y /= mag1;
u1z /= mag1;
double u2x = p2.x - p1.x;
double u2y = p2.y - p1.y;
double u2z = p2.z - p1.z;
double mag2 = Math.sqrt(u2x * u2x + u2y * u2y + u2z * u2z);
u2x /= mag2;
u2y /= mag2;
u2z /= mag2;
double x = u1y * u2z - u1z * u2y;
double y = u1z * u2x - u1x * u2z;
double z = u1x * u2y - u1y * u2x;
double sin = Math.sqrt(x * x + y * y + z * z);
double cos = -(u1x * u2x + u1y * u2y + u1z * u2z);
double w = Math.atan2(sin, cos) / sin;
res.x += w * x;
res.y += w * y;
res.z += w * z;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class Intersector2d method getBarycentric.
public static Point3d getBarycentric(Point2d p, Point2d p1, Point2d p2, Point2d p3, Point3d uvw) {
if (uvw == null) {
uvw = new Point3d();
}
double d = ((p2.y - p3.y) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.y - p3.y));
uvw.x = ((p2.y - p3.y) * (p.x - p3.x) + (p3.x - p2.x) * (p.y - p3.y)) / d;
uvw.y = ((p3.y - p1.y) * (p.x - p3.x) + (p1.x - p3.x) * (p.y - p3.y)) / d;
uvw.z = 1 - uvw.x - uvw.y;
return uvw;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class PolygonalMesh method writePoly.
public void writePoly(PrintStream ps) throws Exception {
ArrayList<Vertex3d> verts = myVertices;
ps.println(verts.size() + " 3 0 0 0");
for (Vertex3d v : verts) {
Point3d pnt = v.pnt;
ps.println(v.idx + " " + pnt.x + " " + pnt.y + " " + pnt.z);
}
ArrayList<Face> fcs = myFaces;
ps.println(fcs.size() + " 1");
for (Face f : fcs) {
ps.println("1 0 1");
if (f.numVertices() != 3)
throw new RuntimeException();
ps.print(f.numVertices());
HalfEdge he = f.he0;
do {
ps.print(" " + (he.head.idx));
he = he.next;
} while (he != f.he0);
ps.println("");
}
ps.println(0);
ps.println(0);
ps.flush();
}
Aggregations