001package org.opencv.core; 002 003//javadoc:Point3_ 004public class Point3 { 005 006 public double x, y, z; 007 008 public Point3(double x, double y, double z) { 009 this.x = x; 010 this.y = y; 011 this.z = z; 012 } 013 014 public Point3() { 015 this(0, 0, 0); 016 } 017 018 public Point3(Point p) { 019 x = p.x; 020 y = p.y; 021 z = 0; 022 } 023 024 public Point3(double[] vals) { 025 this(); 026 set(vals); 027 } 028 029 public void set(double[] vals) { 030 if (vals != null) { 031 x = vals.length > 0 ? vals[0] : 0; 032 y = vals.length > 1 ? vals[1] : 0; 033 z = vals.length > 2 ? vals[2] : 0; 034 } else { 035 x = 0; 036 y = 0; 037 z = 0; 038 } 039 } 040 041 public Point3 clone() { 042 return new Point3(x, y, z); 043 } 044 045 public double dot(Point3 p) { 046 return x * p.x + y * p.y + z * p.z; 047 } 048 049 public Point3 cross(Point3 p) { 050 return new Point3(y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x); 051 } 052 053 @Override 054 public int hashCode() { 055 final int prime = 31; 056 int result = 1; 057 long temp; 058 temp = Double.doubleToLongBits(x); 059 result = prime * result + (int) (temp ^ (temp >>> 32)); 060 temp = Double.doubleToLongBits(y); 061 result = prime * result + (int) (temp ^ (temp >>> 32)); 062 temp = Double.doubleToLongBits(z); 063 result = prime * result + (int) (temp ^ (temp >>> 32)); 064 return result; 065 } 066 067 @Override 068 public boolean equals(Object obj) { 069 if (this == obj) return true; 070 if (!(obj instanceof Point3)) return false; 071 Point3 it = (Point3) obj; 072 return x == it.x && y == it.y && z == it.z; 073 } 074 075 @Override 076 public String toString() { 077 return "{" + x + ", " + y + ", " + z + "}"; 078 } 079}