本文整理汇总了Java中javax.vecmath.Vector3d.cross方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3d.cross方法的具体用法?Java Vector3d.cross怎么用?Java Vector3d.cross使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.vecmath.Vector3d
的用法示例。
在下文中一共展示了Vector3d.cross方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTorsionAngleRadians
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static double getTorsionAngleRadians(double[] a, double[] b, double[] c, double[] d,
Vector3d r1, Vector3d r2, Vector3d r3) {
// a --r1--> b --r2--> c --r3--> d
// get r1 x r2 ==> r1
// and r2 x r3 ==> r3
// then
// sinTheta/cosTheta = r2.(r1 x r3)/(r1 . r3)
sub(b, a, r1);
sub(c, b, r2);
r2.normalize();
r1.cross(r1, r2); //p1
sub(d, c, r3);
r3.cross(r2, r3); //p2
double p1dotp2 = r1.dot(r3);
r1.cross(r3, r1);
double theta = Math.atan2(
-r2.dot(r1), // sin theta ~ r2.(p2 x p1) / |r2|
p1dotp2); // cos theta ~ p1.p2
return theta;
}
示例2: pointPlaneAngleRadians
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static double pointPlaneAngleRadians(Vector3d a, Vector3d b,
Vector3d c, Vector3d d,
Vector3d v1,Vector3d v2,
Vector3d norm) {
v1.sub(b, c);
v2.sub(b, d);
norm.cross(v1, v2);
v2.add(v1);
v1.sub(b, a);
double angleA_CD = vectorAngleRadians(v2, v1);
double angleNorm = vectorAngleRadians(norm, v1);
if (angleNorm > Math.PI / 2)
angleNorm = Math.PI - angleNorm;
return Math.PI / 2.0 + (angleA_CD > Math.PI / 2.0 ? -angleNorm : angleNorm) ;
}
示例3: hasPoint
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public boolean hasPoint(Point3d p){
Vector3d u =GeometryUtils.vectorSubtract(this.p1.asPoint3d(), this.p0.asPoint3d());
Vector3d v =GeometryUtils.vectorSubtract(this.p2.asPoint3d(), this.p0.asPoint3d());
Vector3d n=new Vector3d();
n.cross(u, v);
Vector3d w=GeometryUtils.vectorSubtract(p, this.p0.asPoint3d());
double r=Math.abs(GeometryUtils.vectorCross(u,w).dot(n))/n.lengthSquared();
double b=Math.abs(GeometryUtils.vectorCross(w,v).dot(n))/n.lengthSquared();
double a=1-r-b;
if(a>=0&&a<=1&&b>=0&&b<=1&&r>=0&&r<=1){
return true;
}
return false;
}
示例4: distancePointSegment3D
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
static double distancePointSegment3D(Point3d pt, Segment seg) throws GeometryException {
Vector3d diff = GeometryUtils.vectorSubtract(pt, seg.p0.asPoint3d());
Vector3d segvec = GeometryUtils.vectorSubtract(seg.p1.asPoint3d(), seg.p0.asPoint3d());
double d = diff.dot(segvec);
if (d <= 0)
return (diff.length());
if ((d * diff.length()) > (segvec.length()))
return distancePointPoint3D(pt, seg.p1.asPoint3d());
Vector3d cr = new Vector3d();
cr.cross(segvec,diff);
return cr.length() / (segvec.length());
}
示例5: area
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static double area( Triangle g )
{
Vector3d v1=GeometryUtils.vectorSubtract(g.p1.asPoint3d(),g.p0.asPoint3d());
Vector3d v2=GeometryUtils.vectorSubtract(g.p2.asPoint3d(),g.p0.asPoint3d());
Vector3d cross=new Vector3d();
cross.cross(v1, v2);
return cross.length()/2;
}
示例6: getNormal
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public Vector3d getNormal(){
if(this.normal!=null){
return normal;
}
Vector3d v1=GeometryUtils.vectorSubtract(p1, p0);
Vector3d v2=GeometryUtils.vectorSubtract(p2, p1);
Vector3d u=new Vector3d();
u.cross(v1, v2);
u.normalize();
this.normal=u;
return normal;
}
示例7: tube
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static void tube (MeshBuilder out,
Collection<LinearForm3D> before, Collection<LinearForm3D> after,
Line3d line, LinearForm3D left, LinearForm3D right, CrossGen gen ) {
if (angle ( before, line) < 0.1 || angle ( after, line ) < 0.1 )
return; // too pointy to touch
Point3d middle = line.fromPPram( 0.5 );
Vector3d along = line.dir();
along.normalize();
Vector3d nAlong = new Vector3d (along);
nAlong.negate();
Vector3d o1 = left.normal(), u1 = new Vector3d();
u1.cross( along, o1 );
Frame frame = Mathz.buildFrame ( o1, u1, along, middle);
Vector3d u2 = right.normal();
u2.cross( u2, along );
// u2.add( middle );
Vector2d leftDir = Mathz.toXY ( frame, u1 );
Vector2d rightDir = Mathz.toXY ( frame, u2 );
List<Point3d> profilePts = gen.gen( leftDir, rightDir ).stream().
map( p -> Mathz.fromXY( frame, p ) ).collect( Collectors.toList() );
List<LinearForm3D> dummy = new ArrayList<>();
for (Pair <Point3d, Point3d> pair : new ConsecutivePairs<Point3d>( profilePts, true ) ) {
Point3d
f1 = clip ( pair.first (), along , after , dummy ),
f2 = clip ( pair.second(), along , after , dummy ),
b1 = clip ( pair.first (), nAlong, before, dummy ),
b2 = clip ( pair.second(), nAlong, before, dummy );
out.add (f2, f1, b1, b2);
}
// cap( out, after , along, profilePts, true );
// cap( out, before, nAlong, profilePts, false );
}
示例8: createWindow
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
protected void createWindow( DRectangle winPanel, Matrix4d to3d,
MeshBuilder wall,
MeshBuilder window,
MeshBuilder glass,
double depth,
float sillDepth, float sillHeight,
float corniceHeight,
double panelWidth, double panelHeight ) {
Point2d[] pts = winPanel.points();
Point3d[] ptt = new Point3d[4];
for (int i = 0; i < 4; i++) {
ptt[i] = Pointz.to3( pts[i] );
to3d.transform( ptt[i] );
}
Vector3d along = new Vector3d(ptt[3]);
along.sub(ptt[0]);
along.normalize();
Vector3d up = new Vector3d(ptt[1]);
up.sub(ptt[0]);
up.normalize();
Vector3d out = new Vector3d();
out.cross( along, up );
out.scale(-1/out.length());
Vector3d loc = new Vector3d();
loc.cross( along, up );
loc.scale ( -depth / loc.length() );
loc.add(ptt[0]);
WindowGen.createWindow( window, glass, new Window( Jme3z.to ( loc ), Jme3z.to(along), Jme3z.to(up),
winPanel.width, winPanel.height, 0.3, panelWidth, panelHeight ) );
Vector3f u = Jme3z.to(up), o = Jme3z.to( out );
wall.addInsideRect( Jme3z.to ( ptt[0] ), o, Jme3z.to(along), u,
(float)depth, (float)winPanel.width,(float) winPanel.height );
if (sillDepth > 0 && sillHeight > 0)
window.addCube( Jme3z.to ( ptt[0] ).add( u.mult( -sillHeight + 0.01f ) ).add( o.mult( -sillDepth) ),
Jme3z.to(out), Jme3z.to(along), Jme3z.to(up),
(float)depth + sillDepth, (float)winPanel.width,(float) sillHeight );
if (corniceHeight > 0)
moulding( to3d, new DRectangle(winPanel.x, winPanel.getMaxY(), winPanel.width, corniceHeight), wall );
}
示例9: restorativeForceAndTorsionAngleRadians
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static double restorativeForceAndTorsionAngleRadians(Vector3d i, Vector3d j,
Vector3d k, Vector3d l) {
// This is adapted from http://scidok.sulb.uni-saarland.de/volltexte/2007/1325/pdf/Dissertation_1544_Moll_Andr_2007.pdf
// Many thanks to Andreas Moll and the BALLView developers for this
// Bond vectors of the three atoms
i.sub(j, i);
j.sub(k, j);
k.sub(l, k);
double len_ij = i.length();
double len_jk = j.length();
double len_kl = k.length();
if (isNearZero(len_ij) || isNearZero(len_jk) || isNearZero(len_kl)) {
i.set(0, 0, 0);
j.set(0, 0, 0);
k.set(0, 0, 0);
l.set(0, 0, 0);
return 0.0;
}
double ang = vectorAngleRadians(i, j);
double sin_j = Math.sin(ang);
double cos_j = Math.cos(ang);
ang = vectorAngleRadians(j, k);
double sin_k = Math.sin(ang);
double cos_k = Math.cos(ang);
// normalize the bond vectors:
i.normalize();
j.normalize();
k.normalize();
// use i, k, and l for temporary variables as well
i.cross(i, j); //a
l.cross(j, k); //b
k.cross(i, l); //c
double theta = -Math.atan2(
k.dot(j), // ((ij x jk) x (jk x kl)) . jk
i.dot(l)); // (ij x jk) . (jk x kl)
i.scale(1. / len_ij / sin_j / sin_j);
l.scale(-1. / len_kl / sin_k / sin_k);
j.set(i);
j.scale(-len_ij / len_jk * cos_j - 1.);
k.set(l);
k.scale(-len_kl / len_jk * cos_k);
j.sub(k);
k.set(i);
k.add(j);
k.add(l);
k.scale(-1);
return theta;
}
示例10: intersect3D_2Planes
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static Line3d intersect3D_2Planes(Plane pn1, Plane pn2) {
Vector3d u = new Vector3d();
u.cross(pn1.getNormal(), pn2.getNormal()); // cross product
double ax = (u.x >= 0 ? u.x : -u.x);
double ay = (u.y >= 0 ? u.y : -u.y);
double az = (u.z >= 0 ? u.z : -u.z);
// Pn1 and Pn2 intersect in a line
// first determine max abs coordinate of cross product
int maxc; // max coordinate
if (ax > ay) {
if (ax > az)
maxc = 1;
else
maxc = 3;
} else {
if (ay > az)
maxc = 2;
else
maxc = 3;
}
// next, to get a point on the intersect line
// zero the max coord, and solve for the other two
Point3d iP = new Point3d(); // intersect point
double d1, d2; // the constants in the 2 plane equations
d1 = -pn1.normal.dot(new Vector3d(pn1.p0.x, pn1.p0.y, pn1.p0.z)); // note:
// could
// be
// pre-stored
// with
// plane
d2 = -pn2.normal.dot(new Vector3d(pn2.p0.x, pn2.p0.y, pn2.p0.z)); // ditto
switch (maxc) { // select max coordinate
case 1: // intersect with x=0
iP.x = 0;
iP.y = (d2 * pn1.normal.z - d1 * pn2.normal.z) / u.x;
iP.z = (d1 * pn2.normal.y - d2 * pn1.normal.y) / u.x;
break;
case 2: // intersect with y=0
iP.x = (d1 * pn2.normal.z - d2 * pn1.normal.z) / u.y;
iP.y = 0;
iP.z = (d2 * pn1.normal.x - d1 * pn2.normal.x) / u.y;
break;
case 3: // intersect with z=0
iP.x = (d2 * pn1.normal.y - d1 * pn2.normal.y) / u.z;
iP.y = (d1 * pn2.normal.x - d2 * pn1.normal.x) / u.z;
iP.z = 0;
}
Line3d l = new Line3d(iP, new Point3d(iP.x + u.x, iP.y + u.y, iP.z + u.z));
return l;
}
示例11: intersect3D_2Planes
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static Line3d intersect3D_2Planes(Plane pn1, Plane pn2)
{
Vector3d u= new Vector3d();
u.cross(pn1.getNormal(), pn2.getNormal()); // cross product
double ax = (u.x >= 0 ? u.x : -u.x);
double ay = (u.y >= 0 ? u.y : -u.y);
double az = (u.z >= 0 ? u.z : -u.z);
// Pn1 and Pn2 intersect in a line
// first determine max abs coordinate of cross product
int maxc; // max coordinate
if (ax > ay) {
if (ax > az)
maxc = 1;
else maxc = 3;
}
else {
if (ay > az)
maxc = 2;
else maxc = 3;
}
// next, to get a point on the intersect line
// zero the max coord, and solve for the other two
Point3d iP=new Point3d(); // intersect point
double d1, d2; // the constants in the 2 plane equations
d1 = -pn1.normal.dot(new Vector3d(pn1.p0.x,pn1.p0.y,pn1.p0.z)); // note: could be pre-stored with plane
d2 = -pn2.normal.dot(new Vector3d(pn2.p0.x,pn2.p0.y,pn2.p0.z)); // ditto
switch (maxc) { // select max coordinate
case 1: // intersect with x=0
iP.x = 0;
iP.y = (d2*pn1.normal.z - d1*pn2.normal.z) / u.x;
iP.z = (d1*pn2.normal.y - d2*pn1.normal.y) / u.x;
break;
case 2: // intersect with y=0
iP.x = (d1*pn2.normal.z - d2*pn1.normal.z) / u.y;
iP.y = 0;
iP.z = (d2*pn1.normal.x - d1*pn2.normal.x) / u.y;
break;
case 3: // intersect with z=0
iP.x = (d2*pn1.normal.y - d1*pn2.normal.y) / u.z;
iP.y = (d1*pn2.normal.x - d2*pn1.normal.x) / u.z;
iP.z = 0;
}
Line3d l=new Line3d(iP,new Point3d(iP.x+u.x,iP.y+u.y,iP.z+u.z));
return l;
}
示例12: vectorCross
import javax.vecmath.Vector3d; //导入方法依赖的package包/类
public static Vector3d vectorCross(Vector3d u, Vector3d w) {
Vector3d v=new Vector3d();
v.cross(u, w);
return v;
}