/* * Copyright (c) 2016 Martin Davis. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * and Eclipse Distribution License v. 1.0 which accompanies this distribution. * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v20.html * and the Eclipse Distribution License is available at * * http://www.eclipse.org/org/documents/edl-v10.php. */ package org.locationtech.jts.math; import org.locationtech.jts.geom.Coordinate; /** * Models a plane in 3-dimensional Cartesian space. * * @author mdavis * */ public class Plane3D { /** * Enums for the 3 coordinate planes */ public static final int XY_PLANE = 1; public static final int YZ_PLANE = 2; public static final int XZ_PLANE = 3; private Vector3D normal; private Coordinate basePt; public Plane3D(Vector3D normal, Coordinate basePt) { this.normal = normal; this.basePt = basePt; } /** * Computes the oriented distance from a point to the plane. * The distance is: *
* Geometries lying in this plane undergo least distortion * (and have maximum area) * when projected to the closest axis plane. * This provides optimal conditioning for * computing a Point-in-Polygon test. * * @return the index of the closest axis plane. */ public int closestAxisPlane() { double xmag = Math.abs(normal.getX()); double ymag = Math.abs(normal.getY()); double zmag = Math.abs(normal.getZ()); if (xmag > ymag) { if (xmag > zmag) return YZ_PLANE; else return XY_PLANE; } // y >= x else if (zmag > ymag) { return XY_PLANE; } // y >= z return XZ_PLANE; } }