use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class DistanceGridFeatureQuery method nearestEdgeToPoint.
/**
* Returns the nearest edge to a point, using a specified distance grid.
* An edge may be either a HalfEdge or a LineSegment. The former
* are found in PolygonalMeshes, while the latter are found in PolylineMeshes.
*
* @param nearPnt if not <code>null</code>, returns the nearest point on
* the edge.
* @param sval if not <code>null</code>, returns a coordinate in the
* range [0,1] giving the location of the nearest point along the edge.
* @param dgrid distance grid containing the features.
* @param pnt point for which the nearest edge should be found.
* @return the nearest edge to the point, or <code>null</code> if
* <code>bvh</code> contains no edges.
*/
public Feature nearestEdgeToPoint(Point3d nearPnt, DoubleHolder sval, DistanceGrid dgrid, Point3d pnt) {
if (nearPnt == null) {
nearPnt = new Point3d();
}
Feature feat = dgrid.getNearestWorldFeature(nearPnt, pnt);
if (feat == null) {
return null;
}
if (sval != null) {
if (feat instanceof HalfEdge) {
HalfEdge he = (HalfEdge) feat;
sval.value = he.getProjectionParameter(nearPnt);
} else if (feat instanceof LineSegment) {
LineSegment seg = (LineSegment) feat;
sval.value = seg.getProjectionParameter(nearPnt);
}
}
return feat;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class DistanceGridFeatureQuery method nearestFaceToPoint.
/**
* Returns the nearest triangular face to a point, using a specified
* distance grid. The faces contained within the grid are
* all assumed to be triangular.
*
* @param nearPnt if not <code>null</code>, returns the nearest
* point on the face in world coordinates.
* @param uv if not <code>null</code>, returns the UV coordinates
* of the nearest face point. These are the barycentric coordinates
* with respect to the second and third vertices.
* @param sdgrid distance grid containing the faces.
* @param pnt point for which the nearest face should be found.
* @return the nearest face to the point, or <code>null</code>
* if <code>sdgrid</code> contains no faces.
*/
public Face nearestFaceToPoint(Point3d nearPnt, Vector2d uv, DistanceGrid sdgrid, Point3d pnt) {
if (nearPnt == null) {
nearPnt = new Point3d();
}
Feature feature = sdgrid.getNearestWorldFeature(nearPnt, pnt);
if (feature != null && feature instanceof Face) {
// compute barycentric
Face face = (Face) feature;
if (uv != null) {
// local point
Point3d lnear = nearPnt;
if (sdgrid.getLocalToWorld() != null) {
lnear = new Point3d(nearPnt);
lnear.inverseTransform(sdgrid.getLocalToWorld());
}
face.computeCoords(lnear, uv);
}
return face;
}
return null;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class LineSegment method getProjectionParameter.
public double getProjectionParameter(Point3d pnt) {
Point3d p0 = myVtx0.getWorldPoint();
Point3d p1 = myVtx1.getWorldPoint();
return projectionParameter(p0, p1, pnt);
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MeshBase method size.
/*
* Return the dimensions of the smallest axis-aligned box containing the
* vertices of the mesh, in mesh coordinates.
*/
public Point3d size() {
double inf = Double.POSITIVE_INFINITY;
Point3d pmin = new Point3d(inf, inf, inf);
Point3d pmax = new Point3d(-inf, -inf, -inf);
updateBounds(pmin, pmax);
pmin.sub(pmax, pmin);
return pmin;
}
use of maspack.matrix.Point3d in project artisynth_core by artisynth.
the class MeshFactory method createRectangle.
/**
* Create a open rectangular mesh, composed of triangles, in the x-y
* plane, centered on the origin and with normals directed along the z axis.
* Texture coordinates can optionally be created created for each triangle
* so that (0,0) and (1,1) correspond to the lower left and upper right
* corners.
*
* @param wx width in the x direction
* @param wy width in the y direction
* @param xdiv number of divisions in x (>=1)
* @param ydiv number of divisions in y (>=1)
* @param addNormals if <code>true</code>, generates normals in
* the positive z direction
* @param addTextureCoords if <code>true</code>, generates texture
* coordinates
* @return created mesh
*/
public static PolygonalMesh createRectangle(double wx, double wy, int xdiv, int ydiv, boolean addNormals, boolean addTextureCoords) {
Point3d[] plist = new Point3d[(xdiv + 1) * (ydiv + 1)];
int[][] faceIndices = new int[xdiv * ydiv * 2][];
ArrayList<Vector3d> vt = new ArrayList<Vector3d>();
double xoffset = -wx / 2;
double yoffset = -wy / 2;
double dx = wx / xdiv;
double dy = wy / ydiv;
double dxt = 1.0 / xdiv;
double dyt = 1.0 / ydiv;
for (int j = 0; j <= ydiv; j++) {
for (int i = 0; i <= xdiv; i++) {
plist[i + j * (xdiv + 1)] = new Point3d(xoffset + i * dx, yoffset + j * dy, 0);
if (addTextureCoords) {
vt.add(new Point3d(i * dxt, j * dyt, 0));
}
if (i < xdiv && j < ydiv) {
int idx1 = i + j * (xdiv + 1);
int idx2 = (i + 1) + j * (xdiv + 1);
int idx3 = (i + 1) + (j + 1) * (xdiv + 1);
int idx4 = i + (j + 1) * (xdiv + 1);
int istart = 2 * (i + j * xdiv);
if ((i + j) % 2 == 0) {
faceIndices[istart] = new int[] { idx1, idx2, idx4 };
faceIndices[istart + 1] = new int[] { idx2, idx3, idx4 };
} else {
faceIndices[istart] = new int[] { idx1, idx2, idx3 };
faceIndices[istart + 1] = new int[] { idx1, idx3, idx4 };
}
}
}
}
PolygonalMesh mesh = new PolygonalMesh();
mesh.set(plist, faceIndices);
if (addTextureCoords) {
mesh.setTextureCoords(vt, mesh.createVertexIndices());
}
if (addNormals) {
ArrayList<Vector3d> normals = new ArrayList<>();
normals.add(new Vector3d(0, 0, 1));
int[] indices = mesh.createVertexIndices();
mesh.setNormals(normals, indices);
}
return mesh;
}
Aggregations