⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intersect.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * $RCSfile: Intersect.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistribution of source code must retain the above copyright *   notice, this list of conditions and the following disclaimer. * * - Redistribution in binary form must reproduce the above copyright *   notice, this list of conditions and the following disclaimer in *   the documentation and/or other materials provided with the *   distribution. * * Neither the name of Sun Microsystems, Inc. or the names of * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * This software is provided "AS IS," without a warranty of any * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY * EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. * * You acknowledge that this software is not designed, licensed or * intended for use in the design, construction, operation or * maintenance of any nuclear facility. * * $Revision: 1.4 $ * $Date: 2007/02/09 17:20:13 $ * $State: Exp $ */package com.sun.j3d.utils.behaviors.picking;import javax.media.j3d.*;import javax.vecmath.*;import java.lang.Math;import com.sun.j3d.internal.J3dUtilsI18N;/* * Contains static methods to aid in the intersection test between * various PickShape classes and geometry primitives (such as quad, * triangle, line and point).  *//** * @deprecated As of Java 3D version 1.2, this class is no * longer needed */public class Intersect{    /**   * Determines if the <code>PickRay</code> and quadrilateral   * objects intersect.   * The quadrilateral is defined as <code>coordinates[index]</code> to   * <code>coordinates[index+3]</code>.   *   * @param ray The ray to use in the intersection test.   * @param coordinates An array holding the quadrilateral data.   * @param index An array index that designates the starting position   *  in the array of the quadrilateral to test.   * @param dist On return dist[0] will be set to the distance between ray's    * origin and the point of intersection, if it exists.     * The dist array should be allocated by the user.   * @return <code>true</code> if the ray intersects the quad,   *  <code>false</code> if the ray does not intersect the object.   */   public static boolean rayAndQuad( PickRay ray, Point3d coordinates[], 				    int index, double dist[] ) {        if((coordinates.length - index) < 4)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect0"));       Point3d pnts[] = new Point3d[4];        for(int i=0; i<4; i++)      pnts[i] = coordinates[index+i];       return rayAndPoly(pnts, ray, dist);      }  /**   * Return true if triangle intersects with ray and the distance, from   * the origin of ray to the intersection point, is stored in dist[0].   * The triangle is defined by coordinates[index] to coordinates[index+2]   * <code>coordinates[index+2]</code>.   *   * @param ray The ray to use in the intersection test.   * @param coordinates An array holding the triangle data.   * @param index An array index that designates the starting position   *  in the array of the triangle to test.   * @param dist On return dist[0] will be set to the distance between ray's origin and the   *  point of intersection, if it exists.  The dist array should be   *  allocated by the user.   * @return <code>true</code> if the ray intersects the triangle,   *  <code>false</code> if the ray does not intersect the object.   */  public static boolean rayAndTriangle( PickRay ray, Point3d coordinates[],					int index, double dist[] ) {        if((coordinates.length - index) < 3)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect1"));       Point3d pnts[] = new Point3d[3];        for(int i=0; i<3; i++)      pnts[i] = coordinates[index+i];        return rayAndPoly(pnts, ray, dist);      }  /**   * Return true if triangle intersects with ray and the distance, from   * the origin of ray to the intersection point, is stored in dist[0].   * The triangle is defined by coordinates[index] to coordinates[index+2]   *   * @param ray The ray that is used in intersection test.   * @param coordinates an array of vertices.   * @param index the vertex index   * @param dist On return dist[0] will be set to the distance between ray's origin and the point intersection, if   * exist.   * @return true if ray intersects triangle, else return false.   */     public static boolean rayAndTriangle( PickRay ray, Point3f coordinates[],					int index, double dist[] ) {        if((coordinates.length - index) < 3)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect1"));       Point3d pnts[] = new Point3d[3];        for(int i=0; i<3; i++)      pnts[i] = new Point3d(coordinates[index+i]);        return rayAndPoly(pnts, ray, dist);      }      /**   * Caluates the intersection between a <code>PickSegment</code>   * object and a quadrilateral.   * The quad is defined as coordinates[index] to coordinates[index+3]   *   * @param segment The segment to use in the intersection test.   * @param coordinates An array holding the quadrilateral data.   * @param index An array index that designates the starting position   *  in the array of the quadrilateral to test.   * @param dist On return dist[0] will be set to the distance between the start of the segment   *   and the point of intersection, if it exists.  The dist array   *   should be allocated by the user.   * @return <code>true</code> if the segment intersects the quad,   *  <code>false</code> if the segment does not intersect the object.   */  public static boolean segmentAndQuad( PickSegment segment,                                        Point3d coordinates[],					int index, double dist[] ) {    if((coordinates.length - index) < 4)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect3"));       Point3d pnts[] = new Point3d[4];    for(int i=0; i<4; i++)      pnts[i] = coordinates[index+i];        return segmentAndPoly(pnts, segment, dist);      }  /**   * Return true if quad intersects with segment and the distance, from   * the start of segment to the intersection point, is stored in dist[0].   * The quad is defined by coordinates[index] to coordinates[index+3]   *   * @param segment The segment that is used in intersection test.   * @param coordinates an array of vertices.   * @param index the vertex index   * @param dist On return dist[0] will be set to the distance between segment's start and the point    * intersection, if exist.   * @return true if segment intersects quad, else return false.   */     public static boolean segmentAndQuad( PickSegment segment, Point3f coordinates[],					int index, double dist[] ) {    if((coordinates.length - index) < 4)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect3"));       Point3d pnts[] = new Point3d[4];        for(int i=0; i<4; i++)      pnts[i] = new Point3d(coordinates[index+i]);        return segmentAndPoly(pnts, segment, dist);      }    /**   * Caluates the intersection between a <code>PickSegment</code>   * object and a triangle.   * The triangle is defined as coordinates[index] to coordinates[index+2]   *   * @param segment The segment to use in the intersection test.   * @param coordinates An array holding the triangle data.   * @param index An array index that designates the starting position   *  in the array of the triangle to test.   * @param dist On return dist[0] contains the distance between the start of the segment   *   and the point of intersection, if it exists.  The dist array   *   should be allocated by the user.   * @return <code>true</code> if the segment intersects the triangle,   *  <code>false</code> if the segment does not intersect the object.   */  public static boolean segmentAndTriangle( PickSegment segment,                                             Point3d coordinates[],                                            int index,  					    double dist[] ) {    if((coordinates.length - index) < 3)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect5"));        Point3d pnts[] = new Point3d[3];        for(int i=0; i<3; i++)      pnts[i] = coordinates[index+i];        return segmentAndPoly(pnts, segment, dist);      }  /**   * Return true if triangle intersects with segment and the distance, from   * the start of segment to the intersection point, is stored in dist[0].   * The triangle is defined by coordinates[index] to coordinates[index+2]   *   * @param segment The segment that is used in intersection test.   * @param coordinates an array of vertices.   * @param index the vertex index   * @param dist On return dist[0] will be set to the distance between segment's start and the point    * intersection, if exist.   * @return true if segment intersects triangle, else return false.   */     public static boolean segmentAndTriangle( PickSegment segment, 					    Point3f coordinates[], int index,  					    double dist[] ) {    if((coordinates.length - index) < 3)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect6"));        Point3d pnts[] = new Point3d[3];        for(int i=0; i<3; i++)      pnts[i] = new Point3d(coordinates[index+i]);        return segmentAndPoly(pnts, segment, dist);      }   /**   * Caluates the intersection between a <code>PickPoint</code>   * object and a quadrilateral.   * The quad is defined as <code>coordinates[index]</code> to   * <code>coordinates[index+3]</code>.   *   * @param point The point to use in the intersection test.   * @param coordinates An array holding the quadrilateral data.   * @param index An array index that designates the starting position   *  in the array of the quadrilateral to test.   * @return <code>true</code> if the point intersects the quad,   *  <code>false</code> if the point does not intersect the object.   */  private static boolean pointAndQuad( PickPoint point,                                       Point3d coordinates[],				       int index) {    if((coordinates.length - index) < 4)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect7"));           Point3d pnts[] = new Point3d[4];        for(int i=0; i<4; i++)      pnts[i] = coordinates[index+i];        return pointAndPoly( pnts, point);  }  /**   * Return true if quad intersects with point.   * The triangle is defined by coordinates[index] to coordinates[index+3]   *   * @param point The point that is used in intersection test.   * @param coordinates an array of vertices.   * @param index the vertex index   * @return true if point intersects quad, else return false.   */   private static boolean pointAndQuad( PickPoint point, Point3f coordinates[],				       int index) {    if((coordinates.length - index) < 4)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect7"));           Point3d pnts[] = new Point3d[4];        for(int i=0; i<4; i++)      pnts[i] = new Point3d(coordinates[index+i]);        return pointAndPoly( pnts, point);      }  /**   * Caluates the intersection between a <code>PickPoint</code>   * object and a triangle.   * The triangle is defined by <code>coordinates[index]</code> to   * <code>coordinates[index+2]</code>.   *   * @param point The point to use in the intersection test.   * @param coordinates An array holding the triangle data.   * @param index An array index that designates the starting position   *  in the array of the triangle to test.   * @return <code>true</code> if the point intersects the triangle,   *  <code>false</code> if the point does not intersect the object.   */  private static boolean pointAndTriangle( PickPoint point,                                           Point3d coordinates[],					   int index) {    if((coordinates.length - index) < 3)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect9"));           Point3d pnts[] = new Point3d[3];        for(int i=0; i<3; i++)      pnts[i] = coordinates[index+i];        return pointAndPoly( pnts, point);      }  /**   * Return true if triangle intersects with point.   * The triangle is defined by coordinates[index] to coordinates[index+2]   *   * @param point The point that is used in intersection test.   * @param coordinates an array of vertices.   * @param index the vertex index   * @return true if point intersects triangle, else return false.   */   private static boolean pointAndTriangle( PickPoint point, Point3f coordinates[],					   int index) {    if((coordinates.length - index) < 3)       throw new RuntimeException(J3dUtilsI18N.getString("Intersect10"));           Point3d pnts[] = new Point3d[3];        for(int i=0; i<3; i++)      pnts[i] = new Point3d(coordinates[index+i]);        return pointAndPoly( pnts, point);      }  /**   * Determines if the <code>PickRay</code> and <code>Point3d</code>   * objects intersect.   *   * @param ray The ray that is used in the intersection test.   * @param pnt The point that is used in intersection test.   * @param dist On return dist[0] will be set to the distance between ray's origin and the point    * of intersection, if it exists. The dist array   * should be allocated by the user.   * @return <code>true</code> if the ray intersects the point,   *  <code>false</code> if the ray does not intersect the object.   */   public static boolean rayAndPoint( PickRay ray, Point3d pnt,                                                  double dist[] ) {        Point3d origin = new Point3d();    Vector3d direction = new Vector3d();        ray.get(origin, direction);        return rayAndPoint(pnt, origin, direction, dist);  }  /**   * Return true if point intersects with ray and the distance, from   * the origin of ray to the intersection point, is stored in dist[0].   *   * @param ray The ray that is used in intersection test.   * @param pnt The point that is used in intersection test.   * @param dist On return dist[0] contains the distance between ray's origin and the point    * intersection, if exist.   * @return true if ray intersects point, else return false.   */     public static boolean rayAndPoint( PickRay ray, Point3f pnt, double dist[] ) {        Point3d origin = new Point3d();    Vector3d direction = new Vector3d();        ray.get(origin, direction);      return rayAndPoint(new Point3d(pnt), origin, direction, dist);  }    /**   * Determines if the <code>PickSegment</code> and <code>Point3d</code>   * objects intersect.     *   * @param segment The segment that is used in the intersection test.   * @param pnt The point that is used in intersection test.   * @param dist On return dist[0] contains the distance between segment's origin and the point   * of intersection, if it exists. The dist array

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -