public class Triangle
extends java.lang.Object
Translated from this Matlab code subject to the following copyright:
Copyright (c) 2009, Gwendolyn Fischer All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions 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
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original Matlab code is also added as a comment to the end of the source code file
Constructor and Description |
---|
Triangle() |
Modifier and Type | Method and Description |
---|---|
static float |
dot(float[] a,
float[] b)
Compute scalar product between 3 dimensional vectors
|
static float |
pointTriangle(float[] p1,
float[] p2,
float[] p3,
float[] p,
float[] res)
Compute distance and direction between point and triangle.
|
public static float dot(float[] a, float[] b)
a
- a 3 dimensional vectorb
- another 3 dimensional vecorpublic static float pointTriangle(float[] p1, float[] p2, float[] p3, float[] p, float[] res)
res
will be filled
with the plane equation for the closest plane facing the point p
, where the three first
elements are the normalized surface normal vector coordinates and the forth is the plane constant.
The point x, y, z
is in the plane if the coordinates satisfies the equation
x*res[0] + y*res[1] + z*res[2] = res[3]
. If the closest point
is inside the triangle the plane is identical to the triangle plane. If the closest point is
on an edge or corner the plane is normal to the vector between p
and the closest point.p1
- first corner of trianglep2
- second corner of trianglep3
- third corner of trianglep
- a pointres
- equation of the closest plane to the point p, a float[4]