Project: engagement_generation License: BSD Dependencies:
Used by:
None |
engagement_generation/src/edu/wpi/hri/gen/policy/ref/Point.javaGo to the documentation of this file.00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Worcester Polytechnic Institute 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Worcester Polytechnic Institute. nor the names 00018 * of its contributors may be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 package edu.wpi.hri.gen.policy.ref; 00035 00042 public class Point { 00043 00044 private final double x; 00045 private final double y; 00046 private final double z; 00047 private final double zRot; 00048 00059 public Point(double x, double y, double z) { 00060 this(x, y, z, 0); 00061 } 00062 00073 public Point(double x, double y, double z, double zRot) { 00074 this.x = x; 00075 this.y = y; 00076 this.z = z; 00077 this.zRot = zRot; 00078 } 00079 00085 public double getX() { 00086 return x; 00087 } 00088 00094 public double getY() { 00095 return y; 00096 } 00097 00103 public double getZ() { 00104 return z; 00105 } 00106 00112 public double getzRot() { 00113 return zRot; 00114 } 00115 00116 private static double square(double d) { 00117 return d * d; 00118 } 00119 00127 public double fullDistanceSquared(Point dest) { 00128 return square(this.x - dest.x) + square(this.y - dest.y) 00129 + square(this.z - dest.z); 00130 } 00131 00139 public double fullDistance(Point dest) { 00140 return Math.sqrt(this.fullDistanceSquared(dest)); 00141 } 00142 00150 public double xyDistanceSquared(Point dest) { 00151 return square(this.x - dest.x) + square(this.y - dest.y); 00152 } 00153 00161 public double xyDistance(Point dest) { 00162 return Math.sqrt(this.xyDistanceSquared(dest)); 00163 } 00164 00172 public double xzDistanceSquared(Point dest) { 00173 return square(this.x - dest.x) + square(this.z - dest.z); 00174 } 00175 00183 public double xzDistance(Point dest) { 00184 return Math.sqrt(this.xzDistanceSquared(dest)); 00185 } 00186 00194 public double yzDistanceSquared(Point dest) { 00195 return square(this.y - dest.y) + square(this.z - dest.z); 00196 } 00197 00205 public double yzDistance(Point dest) { 00206 return Math.sqrt(this.yzDistanceSquared(dest)); 00207 } 00208 00209 @Override 00210 public String toString() { 00211 return "(" + x + ", " + y + ", " + z + ")"; 00212 } 00213 00214 @Override 00215 public boolean equals(Object obj) { 00216 if (obj instanceof Point) { 00217 Point other = (Point) obj; 00218 return (this.x == other.x) && (this.y == other.y) 00219 && (this.z == other.z) && (this.zRot == other.zRot); 00220 } else 00221 return false; 00222 } 00223 } |