use of maspack.matrix.Plane in project artisynth_core by artisynth.
the class BVIntersectorTest method testPlaneIntersection.
public void testPlaneIntersection(PolygonalMesh mesh, BVTree bvh, RigidTransform3d XMW) {
Point3d center = new Point3d();
double radius = bvh.getRadius();
bvh.getCenter(center);
mesh.setMeshToWorld(XMW);
bvh.setBvhToWorld(XMW);
Random rand = RandomGenerator.get();
int numtrials = 100;
for (int i = 0; i < numtrials; i++) {
Plane plane = new Plane();
plane.normal.setRandom();
plane.offset = 3 * radius * (rand.nextDouble() - 0.5);
testPlaneIntersection(mesh, bvh, plane);
}
}
use of maspack.matrix.Plane in project artisynth_core by artisynth.
the class BVIntersectorTest method intersectLeafNodes.
ArrayList<TriPlaneIntersection> intersectLeafNodes(BVTree bvh, Plane plane, BVIntersector intersector) {
if (bvh.getBvhToWorld() != RigidTransform3d.IDENTITY) {
plane = new Plane(plane);
plane.inverseTransform(bvh.getBvhToWorld());
}
ArrayList<TriPlaneIntersection> intersections = new ArrayList<TriPlaneIntersection>();
ArrayList<BVNode> nodes = new ArrayList<BVNode>();
getAllIntersectingLeafNodes(nodes, bvh, plane);
for (int i = 0; i < nodes.size(); i++) {
intersector.intersectBoundingVolumeTriangles(intersections, nodes.get(i), plane);
}
for (TriPlaneIntersection isec : intersections) {
for (int k = 0; k < isec.points.length; k++) {
isec.points[k].transform(bvh.getBvhToWorld());
}
}
return intersections;
}
use of maspack.matrix.Plane in project artisynth_core by artisynth.
the class LineSegment method computeFocalPoint.
/**
* Given a plane expressed in eye coordinates, compute a representative focal
* point (in eye coordinates) for this plane, and return the distance
* per-pixal for this focal point. Returning -1 means that the plane is
* invisible.
*
* <p>
* The method works by finding the centroid of the (clipped) polygon
* associated with the grid boundary, as seen in screen coordinates. This
* centroid is the projected back onto the plane.
*/
private double computeFocalPoint(Point3d focus, RigidTransform3d TGW, Renderer renderer) {
RigidTransform3d XGridToEye = new RigidTransform3d();
RigidTransform3d TWorldToEye = renderer.getViewMatrix();
XGridToEye.mul(TWorldToEye, TGW);
if (focus == null) {
focus = new Point3d();
}
if (renderer.isOrthogonal()) {
Plane plane = new Plane();
plane.set(XGridToEye);
computeFocalPoint(focus, plane, 0, 0, 1);
return renderer.getViewPlaneWidth() / renderer.getScreenWidth();
}
double near = renderer.getViewPlaneDistance();
double far = renderer.getFarPlaneDistance();
double vw = renderer.getViewPlaneWidth();
double vh = renderer.getViewPlaneHeight();
// double fov = renderer.getFieldOfViewY();
int height = renderer.getScreenHeight();
double nearDistPerPixel = renderer.getViewPlaneHeight() / height;
GridCentroidComputer newComp = new GridCentroidComputer(myMinSize, near, far);
Point3d cent = new Point3d();
if (!newComp.computeCentroid(cent, XGridToEye, vw, vh)) {
return -1;
}
double zmax = newComp.getZmax();
double zmin = newComp.getZmin();
RotationMatrix3d R = XGridToEye.R;
Plane plane = new Plane(new Vector3d(R.m02, R.m12, R.m22), new Point3d(XGridToEye.p));
double s = plane.intersectLine(focus, cent, Point3d.ZERO);
if (s == Double.POSITIVE_INFINITY) {
focus.scale(-(zmin + zmax) / (2 * near), cent);
}
double zref = -focus.z;
return zref / near * nearDistPerPixel;
}
use of maspack.matrix.Plane in project artisynth_core by artisynth.
the class LineSegment method intersectBoundary.
private void intersectBoundary(ConvexPoly2d poly, RigidTransform3d XGridToEye, double nx, double ny, double nz, double d) {
Plane plane = new Plane(nx, ny, nz, d);
if (XGridToEye != RigidTransform3d.IDENTITY) {
plane.inverseTransform(XGridToEye);
}
Vector3d u = new Vector3d();
Point3d p = new Point3d();
Plane polyPlane = new Plane(0, 0, 1, 0);
if (polyPlane.intersectPlane(p, u, plane)) {
poly.intersectHalfPlane(u.y, -u.x, p.x * u.y - p.y * u.x);
}
}
use of maspack.matrix.Plane in project artisynth_core by artisynth.
the class SegmentedPlanarCoupling method doProject.
private Plane doProject(RigidTransform3d TGD, RigidTransform3d TCD) {
myTmp.set(TCD.p);
Plane plane = closestPlane(myTmp);
plane.project(myTmp, myTmp);
if (TGD != null) {
TGD.p.set(myTmp);
TGD.R.set(TCD.R);
}
return plane;
}
Aggregations