_id
stringlengths
2
7
title
stringlengths
3
140
partition
stringclasses
3 values
text
stringlengths
73
34.1k
language
stringclasses
1 value
meta_information
dict
q177600
Intersection2D_F64.containTriangle
test
public static boolean containTriangle( Point2D_F64 a , Point2D_F64 b , Point2D_F64 c , Point2D_F64 pt ) { boolean ret = false; if ( ((a.y>pt.y) != (b.y>pt.y)) && (pt.x < (b.x-a.x) * (pt.y-a.y) / (b.y-a.y) + a.x) ) ret = true; if ( ((b.y>pt.y) != (c.y>pt.y)) && (pt.x < (c.x-b.x) * (pt.y-b.y) / (c.y-b.y) + b.x) ) ret = !ret; if ( ((c.y>pt.y) != (a.y>pt.y)) && (pt.x < (a.x-c.x) * (pt.y-c.y) / (a.y-c.y) + c.x) ) ret = !ret; return ret; }
java
{ "resource": "" }
q177601
Intersection2D_F64.intersection
test
public static Point2D_F64 intersection( LineParametric2D_F64 a, LineParametric2D_F64 b , Point2D_F64 ret ) { double t_b = a.getSlopeX() * ( b.getY() - a.getY() ) - a.getSlopeY() * ( b.getX() - a.getX() ); double bottom = a.getSlopeY() * b.getSlopeX() - b.getSlopeY() * a.getSlopeX(); if( bottom == 0 ) return null; t_b /= bottom; double x = b.getSlopeX() * t_b + b.getX(); double y = b.getSlopeY() * t_b + b.getY(); if( ret == null ) ret = new Point2D_F64(); ret.set(x,y); return ret; }
java
{ "resource": "" }
q177602
Intersection2D_F64.intersection
test
public static Point2D_F64 intersection( LineSegment2D_F64 l_0, LineSegment2D_F64 l_1, Point2D_F64 ret ) { double a0 = l_0.b.x - l_0.a.x; double b0 = l_0.b.y - l_0.a.y; double a1 = l_1.b.x - l_1.a.x; double b1 = l_1.b.y - l_1.a.y; double top = b0 * ( l_1.a.x - l_0.a.x ) + a0 * ( l_0.a.y - l_1.a.y ); double bottom = a0 * b1 - b0 * a1; if( bottom == 0 ) return null; double t_1 = top / bottom; // does not intersect along the second line segment if( t_1 < 0 || t_1 > 1 ) return null; top = b1 * ( l_0.a.x - l_1.a.x ) + a1 * ( l_1.a.y - l_0.a.y ); bottom = a1 * b0 - b1 * a0; double t_0 = top / bottom; // does not intersect along the first line segment if( t_0 < 0 || t_0 > 1 ) return null; if( ret == null ) { ret = new Point2D_F64(); } ret.set( l_1.a.x + a1 * t_1, l_1.a.y + b1 * t_1 ); return ret; }
java
{ "resource": "" }
q177603
Intersection2D_F64.intersection
test
public static Point2D_F64 intersection( Point2D_F64 lineA0 , Point2D_F64 lineA1 , Point2D_F64 lineB0 , Point2D_F64 lineB1 , Point2D_F64 output ) { if( output == null ) output = new Point2D_F64(); double slopeAx = lineA1.x - lineA0.x; double slopeAy = lineA1.y - lineA0.y; double slopeBx = lineB1.x - lineB0.x; double slopeBy = lineB1.y - lineB0.y; double top = slopeAy * ( lineB0.x - lineA0.x ) + slopeAx * (lineA0.y - lineB0.y ); double bottom = slopeAx * slopeBy - slopeAy * slopeBx; if( bottom == 0 ) return null; double t = top / bottom; output.x = lineB0.x + t*slopeBx; output.y = lineB0.y + t*slopeBy; return output; }
java
{ "resource": "" }
q177604
Intersection2D_F64.intersection
test
public static double intersection( LineParametric2D_F64 target, LineSegment2D_F64 l ) { double a1 = l.b.x - l.a.x; double b1 = l.b.y - l.a.y; double top = target.slope.y * ( l.a.x - target.p.x ) + target.slope.x * ( target.p.y - l.a.y ); double bottom = target.slope.x * b1 - target.slope.y * a1; if( bottom == 0 ) return Double.NaN; double t_1 = top / bottom; // does not intersect along the second line segment if( t_1 < 0 || t_1 > 1 ) return Double.NaN; top = b1 * ( target.p.x - l.a.x ) + a1 * ( l.a.y - target.p.y ); bottom = a1 * target.slope.y - b1 * target.slope.x; return top / bottom; }
java
{ "resource": "" }
q177605
Intersection2D_F64.intersection
test
public static double intersection( Polygon2D_F64 a , Polygon2D_F64 b ) { AreaIntersectionPolygon2D_F64 alg = new AreaIntersectionPolygon2D_F64(); return Math.abs(alg.computeArea(a,b)); }
java
{ "resource": "" }
q177606
Intersection2D_F64.contains
test
public static boolean contains(EllipseRotated_F64 ellipse , double x , double y ) { return (UtilEllipse_F64.evaluate(x,y, ellipse) <= 1.0 ); }
java
{ "resource": "" }
q177607
Intersection2D_F64.intersectionArea
test
public static double intersectionArea( Rectangle2D_F64 a , Rectangle2D_F64 b ) { if( !intersects(a,b) ) return 0; double x0 = Math.max(a.p0.x,b.p0.x); double x1 = Math.min(a.p1.x,b.p1.x); double y0 = Math.max(a.p0.y,b.p0.y); double y1 = Math.min(a.p1.y,b.p1.y); return (x1-x0)*(y1-y0); }
java
{ "resource": "" }
q177608
ConvertRotation3D_F64.get
test
private static double get( DMatrixRMaj M , int index ) { if( index < 0 ) { return -M.data[-index-1]; } else { return M.data[index-1]; } }
java
{ "resource": "" }
q177609
ConvertRotation3D_F64.matrixToQuaternion
test
public static Quaternion_F64 matrixToQuaternion( DMatrixRMaj R, Quaternion_F64 quat ) { if( quat == null ) quat = new Quaternion_F64(); // algorithm from: // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ // // Designed to minimize numerical error by not dividing by very small numbers double m00 = R.unsafe_get(0,0); double m01 = R.unsafe_get(0,1); double m02 = R.unsafe_get(0,2); double m10 = R.unsafe_get(1,0); double m11 = R.unsafe_get(1,1); double m12 = R.unsafe_get(1,2); double m20 = R.unsafe_get(2,0); double m21 = R.unsafe_get(2,1); double m22 = R.unsafe_get(2,2); double trace = m00 + m11 + m22; if (trace > 0) { double S = Math.sqrt(trace+1.0) * 2; // S=4*qw quat.w = 0.25 * S; quat.x = (m21 - m12) / S; quat.y = (m02 - m20) / S; quat.z = (m10 - m01) / S; } else if ((m00 > m11)&(m00 > m22)) { double S = Math.sqrt(1.0 + m00 - m11 - m22) * 2; // S=4*qx quat.w = (m21 - m12) / S; quat.x = 0.25 * S; quat.y = (m01 + m10) / S; quat.z = (m02 + m20) / S; } else if (m11 > m22) { double S = Math.sqrt(1.0 + m11 - m00 - m22) * 2; // S=4*qy quat.w = (m02 - m20) / S; quat.x = (m01 + m10) / S; quat.y = 0.25 * S; quat.z = (m12 + m21) / S; } else { double S = Math.sqrt(1.0 + m22 - m00 - m11) * 2; // S=4*qz quat.w = (m10 - m01) / S; quat.x = (m02 + m20) / S; quat.y = (m12 + m21) / S; quat.z = 0.25 * S; } return quat; }
java
{ "resource": "" }
q177610
ConvertRotation3D_F64.rotX
test
public static DMatrixRMaj rotX( double ang, DMatrixRMaj R ) { if( R == null ) R = new DMatrixRMaj( 3, 3 ); setRotX( ang, R ); return R; }
java
{ "resource": "" }
q177611
ConvertRotation3D_F64.setRotX
test
public static void setRotX( double ang, DMatrixRMaj R ) { double c = Math.cos( ang ); double s = Math.sin( ang ); R.set( 0, 0, 1 ); R.set( 1, 1, c ); R.set( 1, 2, -s ); R.set( 2, 1, s ); R.set( 2, 2, c ); }
java
{ "resource": "" }
q177612
ConvertRotation3D_F64.rotY
test
public static DMatrixRMaj rotY( double ang, DMatrixRMaj R ) { R = checkDeclare3x3( R ); setRotY( ang, R ); return R; }
java
{ "resource": "" }
q177613
ConvertRotation3D_F64.rotZ
test
public static DMatrixRMaj rotZ( double ang, DMatrixRMaj R ) { R = checkDeclare3x3( R ); setRotZ( ang, R ); return R; }
java
{ "resource": "" }
q177614
ConvertRotation3D_F64.setRotZ
test
public static void setRotZ( double ang, DMatrixRMaj r ) { double c = Math.cos( ang ); double s = Math.sin( ang ); r.set( 0, 0, c ); r.set( 0, 1, -s ); r.set( 1, 0, s ); r.set( 1, 1, c ); r.set( 2, 2, 1 ); }
java
{ "resource": "" }
q177615
ConvertRotation3D_F64.eulerToMatrix
test
public static DMatrixRMaj eulerToMatrix( EulerType type , double rotA, double rotB, double rotC, DMatrixRMaj R ) { R = checkDeclare3x3( R ); DMatrixRMaj R_a = rotationAboutAxis( type.getAxisA(), rotA, null ); DMatrixRMaj R_b = rotationAboutAxis( type.getAxisB(), rotB, null ); DMatrixRMaj R_c = rotationAboutAxis( type.getAxisC(), rotC, null ); DMatrixRMaj A = new DMatrixRMaj( 3, 3 ); CommonOps_DDRM.mult( R_b, R_a, A ); CommonOps_DDRM.mult( R_c, A, R ); return R; }
java
{ "resource": "" }
q177616
ConvertRotation3D_F64.rotationAboutAxis
test
private static DMatrixRMaj rotationAboutAxis(int axis, double angle, DMatrixRMaj R ) { switch( axis ) { case 0: return ConvertRotation3D_F64.rotX( angle, R ); case 1: return ConvertRotation3D_F64.rotY( angle, R ); case 2: return ConvertRotation3D_F64.rotZ( angle, R ); default: throw new IllegalArgumentException( "Unknown which" ); } }
java
{ "resource": "" }
q177617
LineParametric2D_F64.setAngle
test
public void setAngle( double angle ) { slope.set( Math.cos( angle ), Math.sin( angle ) ); }
java
{ "resource": "" }
q177618
TwistOps_F64.twist
test
public static TwistCoordinate_F64 twist( Se3_F64 motion , TwistCoordinate_F64 twist ) { if( twist == null ) twist = new TwistCoordinate_F64(); if(MatrixFeatures_DDRM.isIdentity(motion.R, GrlConstants.TEST_F64)) { twist.w.set(0,0,0); twist.v.set(motion.T); } else { Rodrigues_F64 rod = new Rodrigues_F64(); ConvertRotation3D_F64.matrixToRodrigues(motion.R,rod); twist.w.set(rod.unitAxisRotation); double theta = rod.theta; // A = (I-SO)*hat(w) + w*w'*theta DMatrixRMaj A = CommonOps_DDRM.identity(3); CommonOps_DDRM.subtract(A,motion.R, A); DMatrixRMaj w_hat = GeometryMath_F64.crossMatrix(twist.w,null); DMatrixRMaj tmp = A.copy(); CommonOps_DDRM.mult(tmp,w_hat,A); Vector3D_F64 w = twist.w; A.data[0] += w.x*w.x*theta; A.data[1] += w.x*w.y*theta; A.data[2] += w.x*w.z*theta; A.data[3] += w.y*w.x*theta; A.data[4] += w.y*w.y*theta; A.data[5] += w.y*w.z*theta; A.data[6] += w.z*w.x*theta; A.data[7] += w.z*w.y*theta; A.data[8] += w.z*w.z*theta; DMatrixRMaj y = new DMatrixRMaj(3,1); y.data[0] = motion.T.x; y.data[1] = motion.T.y; y.data[2] = motion.T.z; DMatrixRMaj x = new DMatrixRMaj(3,1); CommonOps_DDRM.solve(A,y,x); twist.w.scale(rod.theta); twist.v.x = (double) x.data[0]; twist.v.y = (double) x.data[1]; twist.v.z = (double) x.data[2]; twist.v.scale(rod.theta); } return twist; }
java
{ "resource": "" }
q177619
InterpolateLinearSe3_F64.setTransforms
test
public void setTransforms( Se3_F64 initial , Se3_F64 end) { this.initial.set(initial); translation.x = end.T.x - initial.T.x; translation.y = end.T.y - initial.T.y; translation.z = end.T.z - initial.T.z; CommonOps_DDRM.multTransA(initial.getR(), end.getR(), R); ConvertRotation3D_F64.matrixToRodrigues(R,rotation); rotMagnitude = rotation.theta; }
java
{ "resource": "" }
q177620
InterpolateLinearSe3_F64.interpolate
test
public void interpolate( double where , Se3_F64 output ) { rotation.setTheta(where*rotMagnitude); ConvertRotation3D_F64.rodriguesToMatrix(rotation,R); output.T.x = initial.T.x + where*translation.x; output.T.y = initial.T.y + where*translation.y; output.T.z = initial.T.z + where*translation.z; CommonOps_DDRM.mult(initial.R,R,output.R); }
java
{ "resource": "" }
q177621
FitPlane3D_F64.svd
test
public boolean svd( List<Point3D_F64> points , Point3D_F64 outputCenter , Vector3D_F64 outputNormal ) { final int N = points.size(); // find the centroid outputCenter.set(0,0,0); for( int i = 0; i < N; i++ ) { Point3D_F64 p = points.get(i); outputCenter.x += p.x; outputCenter.y += p.y; outputCenter.z += p.z; } outputCenter.x /= N; outputCenter.y /= N; outputCenter.z /= N; return solvePoint(points,outputCenter,outputNormal); }
java
{ "resource": "" }
q177622
FitPlane3D_F64.solvePoint
test
public boolean solvePoint(List<Point3D_F64> points , Point3D_F64 pointOnPlane , Vector3D_F64 outputNormal ) { final int N = points.size(); // construct the matrix A.reshape(N,3); int index = 0; for( int i = 0; i < N; i++ ) { Point3D_F64 p = points.get(i); A.data[index++] = p.x - pointOnPlane.x; A.data[index++] = p.y - pointOnPlane.y; A.data[index++] = p.z - pointOnPlane.z; } // decompose and find the singular value if( !solverNull.process(A,1,nullspace) ) return false; // the normal is the singular vector outputNormal.x = (double) nullspace.unsafe_get(0,0); outputNormal.y = (double) nullspace.unsafe_get(1,0); outputNormal.z = (double) nullspace.unsafe_get(2,0); return true; }
java
{ "resource": "" }
q177623
Polygon2D_F64.getSideLength
test
public double getSideLength( int index ) { Point2D_F64 a = vertexes.get( index ); Point2D_F64 b = vertexes.get( (index+1)%vertexes.size ); return (double)a.distance(b); }
java
{ "resource": "" }
q177624
Polygon2D_F64.isInside
test
public boolean isInside( Point2D_F64 p ) { if( isConvex() ) { return Intersection2D_F64.containConvex(this,p); } else { return Intersection2D_F64.containConcave(this,p); } }
java
{ "resource": "" }
q177625
UtilCurves_F64.convert
test
public static DMatrixRMaj convert(ConicGeneral_F64 src , DMatrixRMaj dst ) { if( dst == null ) dst = new DMatrixRMaj(3,3); else dst.reshape(3,3); double B = src.B/2.0; double D = src.D/2.0; double E = src.E/2.0; dst.data[0] = src.A; dst.data[1] = B; dst.data[2] = D; dst.data[3] = B; dst.data[4] = src.C; dst.data[5] = E; dst.data[6] = D; dst.data[7] = E; dst.data[8] = src.F; return dst; }
java
{ "resource": "" }
q177626
UtilCurves_F64.convert
test
public static DMatrix3x3 convert(ConicGeneral_F64 src , DMatrix3x3 dst ) { if( dst == null ) dst = new DMatrix3x3(); double B = src.B/2.0; double D = src.D/2.0; double E = src.E/2.0; dst.a11 = src.A; dst.a12 = B; dst.a13 = D; dst.a21 = B; dst.a22 = src.C; dst.a23 = E; dst.a31 = D; dst.a32 = E; dst.a33 = src.F; return dst; }
java
{ "resource": "" }
q177627
UtilCurves_F64.convert
test
public static ParabolaGeneral_F64 convert(ConicGeneral_F64 src , ParabolaGeneral_F64 dst ) { if( dst == null ) dst = new ParabolaGeneral_F64(); // NOTE haven't put much through if this is the correct way to handle negative values of A or C dst.A = Math.signum(src.A) * Math.sqrt(Math.abs(src.A)); dst.C = Math.signum(src.C) * Math.sqrt(Math.abs(src.C)); dst.D = src.D; dst.E = src.E; dst.F = src.F; return dst; }
java
{ "resource": "" }
q177628
UtilCurves_F64.convert
test
public static ConicGeneral_F64 convert(ParabolaGeneral_F64 src , ConicGeneral_F64 dst ) { if( dst == null ) dst = new ConicGeneral_F64(); dst.A = src.A*src.A; dst.B = src.A*src.C*2.0; dst.C = src.C*src.C; dst.D = src.D; dst.E = src.E; dst.F = src.F; return dst; }
java
{ "resource": "" }
q177629
GeometryMath_F64.divide
test
public static void divide( GeoTuple3D_F64 p , double v ) { p.x /= v; p.y /= v; p.z /= v; }
java
{ "resource": "" }
q177630
GeometryMath_F64.toMatrix
test
public static DMatrixRMaj toMatrix(GeoTuple3D_F64 in, DMatrixRMaj out) { if( out == null ) out = new DMatrixRMaj(3,1); else if( out.getNumElements() != 3 ) throw new IllegalArgumentException("Vector with 3 elements expected"); out.data[0] = in.x; out.data[1] = in.y; out.data[2] = in.z; return out; }
java
{ "resource": "" }
q177631
GeometryMath_F64.toTuple3D
test
public static void toTuple3D(DMatrixRMaj in, GeoTuple3D_F64 out) { out.x = (double)in.get(0); out.y = (double)in.get(1); out.z = (double)in.get(2); }
java
{ "resource": "" }
q177632
Rodrigues_F64.setParamVector
test
public void setParamVector( double x , double y , double z ) { double ax = Math.abs(x); double ay = Math.abs(y); double az = Math.abs(z); double max = Math.max(ax,ay); max = Math.max(max,az); if( max == 0 ) { theta = 0; unitAxisRotation.set(1,0,0); } else { x /= max; y /= max; z /= max; theta = Math.sqrt(x*x + y*y + z*z); unitAxisRotation.x = x/theta; unitAxisRotation.y = y/theta; unitAxisRotation.z = z/theta; theta *= max; } }
java
{ "resource": "" }
q177633
UtilAngle.distHalf
test
public static double distHalf( double angA , double angB ) { double a = Math.abs(angA-angB); if( a <= Math.PI/2 ) return a; else return Math.PI-a; }
java
{ "resource": "" }
q177634
Intersection3D_F64.intersect
test
public static boolean intersect( PlaneGeneral3D_F64 a , PlaneGeneral3D_F64 b , LineParametric3D_F64 line ) { // Line's slope is the cross product of the two normal vectors GeometryMath_F64.cross(a.A,a.B,a.C,b.A,b.B,b.C,line.slope); if( line.slope.normSq() == 0 ) return false; // Closest point on plane 'a' to origin (0,0,0) double n2 = a.A*a.A + a.B*a.B + a.C*a.C; double closestX = a.A*a.D/n2; double closestY = a.B*a.D/n2; double closestZ = a.C*a.D/n2; // Cross product between normal of 'a' and the line's slope. This points towards the intersection double slopeX = a.B * line.slope.z - a.C * line.slope.y; double slopeY = a.C * line.slope.x - a.A * line.slope.z; double slopeZ = a.A * line.slope.y - a.B * line.slope.x; // Now find the intersection of the plane and a line containing point 'closest' and pointing towards the // the intersection. double top = b.D - b.A*closestX - b.B*closestY - b.C*closestZ; double bottom = b.A*slopeX + b.B*slopeY + b.C*slopeZ; double d = top/bottom; line.p.x = closestX + d*slopeX; line.p.y = closestY + d*slopeY; line.p.z = closestZ + d*slopeZ; return true; }
java
{ "resource": "" }
q177635
Intersection3D_F64.containedPlane
test
private static boolean containedPlane( Point3D_F64 T_v0, Point3D_F64 output, Vector3D_F64 u , Vector3D_F64 v , Vector3D_F64 w0 ) { double uu, uv, vv, wu, wv, D; uu = u.dot(u); uv = u.dot(v); vv = v.dot(v); w0.minus(output,T_v0); wu = w0.dot(u); wv = w0.dot(v); D = uv * uv - uu * vv; // get and test parametric coords double s, t; s = (uv * wv - vv * wu) / D; if (s < 0.0 || s > 1.0) // I is outside T return false; t = (uv * wu - uu * wv) / D; return !(t < 0.0) && !((s + t) > 1.0); // I is outside T }
java
{ "resource": "" }
q177636
Intersection3D_F64.intersect
test
public static boolean intersect(LineParametric3D_F64 line , Sphere3D_F64 sphere , Point3D_F64 a, Point3D_F64 b ) { // this equation was found by solving for l: // ||(P + V*l) - X0|| == r double r2 = sphere.radius*sphere.radius; double PP = GeometryMath_F64.dot(line.p,line.p); double PV = GeometryMath_F64.dot(line.p,line.slope); double PX = GeometryMath_F64.dot(line.p,sphere.center); double VV = GeometryMath_F64.dot(line.slope,line.slope); double VX = GeometryMath_F64.dot(line.slope,sphere.center); double XX = GeometryMath_F64.dot(sphere.center,sphere.center); // Coefficients in the quadratic equation double A = VV; double B = 2.0*(PV-VX); double C = PP+XX-2.0*PX-r2; // solve for the quadratic equation double inner = B*B - 4.0*A*C; if( inner < 0 ) return false; double sqrt = Math.sqrt(inner); double t0 = (-B + sqrt)/(2.0*A); double t1 = (-B - sqrt)/(2.0*A); line.setPointOnLine(t0,a); line.setPointOnLine(t1,b); return true; }
java
{ "resource": "" }
q177637
InterpolateLinearSe2_F64.interpolate
test
public static void interpolate(Se2_F64 a , Se2_F64 b , double where, Se2_F64 output) { double w0 = 1.0-where; output.T.x = a.T.x*w0 + b.T.x*where; output.T.y = a.T.y*w0 + b.T.y*where; // interpolating rotation is more difficult // This only works well if the difference between the two angles is small double yaw0 = a.getYaw(); double yaw1 = b.getYaw(); double cw = UtilAngle.distanceCW(yaw0, yaw1); double ccw = UtilAngle.distanceCCW(yaw0,yaw1); double yaw; if( cw > ccw ) { yaw = yaw0+ccw*where; } else { yaw = yaw0-cw*where; } output.setYaw(yaw); }
java
{ "resource": "" }
q177638
MotionSe3PointCrossCovariance_F64.extractQuaternionFromQ
test
private void extractQuaternionFromQ( SimpleMatrix q ) { SimpleEVD<SimpleMatrix> evd = q.eig(); int indexMax = evd.getIndexMax(); SimpleMatrix v_max = evd.getEigenVector( indexMax ); quat.w = (double) v_max.get( 0 ); quat.x = (double) v_max.get( 1 ); quat.y = (double) v_max.get( 2 ); quat.z = (double) v_max.get( 3 ); quat.normalize(); ConvertRotation3D_F64.quaternionToMatrix( quat, motion.getR() ); }
java
{ "resource": "" }
q177639
AndrewMonotoneConvexHull_F64.process
test
public void process( Point2D_F64[] input , int length , Polygon2D_F64 hull ) { // ahdnle special cases if( length == 2 ) { hull.vertexes.resize(length); for (int i = 0; i < length; i++) { hull.get(i).set(input[i]); } return; } sorter.sort(input,length); work.reset(); // construct the lower hull for (int i = 0; i < length; i++) { Point2D_F64 p = input[i]; //Contains at least 2 points and the last two points and 'p' do not make a counter-clockwise turn while( work.size() >= 2 && subtractThenCross(p,work.getTail(0),work.getTail(1)) >= 0) { // remove the last points from the hull work.removeTail(); } // append p to the end work.add(p); } work.removeTail(); int minSize = work.size+2; // construct upper hull for(int i = length-1 ; i >= 0 ; i --) // Finding top layer from hull { //Contains at least 2 points and the last two points and 'p' do not make a counter-clockwise turn Point2D_F64 p = input[i]; while( work.size() >= minSize && subtractThenCross(p,work.getTail(0),work.getTail(1)) >= 0 ) { work.removeTail(); } // append p to the end work.add(p); } work.removeTail(); // create a copy for the output // the work buffer contains references to the input points, but to be safe the output should have its // own instances hull.vertexes.resize(work.size); for (int i = 0; i < work.size(); i++) { hull.vertexes.data[i].set(work.get(i)); } }
java
{ "resource": "" }
q177640
SpecialEuclideanOps_F64.setToNoMotion
test
public static void setToNoMotion( Se3_F64 se ) { CommonOps_DDRM.setIdentity( se.getR() ); se.getT().set( 0, 0, 0 ); }
java
{ "resource": "" }
q177641
SpecialEuclideanOps_F64.toHomogeneous
test
public static DMatrixRMaj toHomogeneous( Se3_F64 se, DMatrixRMaj ret ) { if( ret == null ) ret = new DMatrixRMaj( 4, 4 ); else { ret.set( 3, 0, 0 ); ret.set( 3, 1, 0 ); ret.set( 3, 2, 0 ); } CommonOps_DDRM.insert( se.getR(), ret, 0, 0 ); Vector3D_F64 T = se.getT(); ret.set( 0, 3, T.x ); ret.set( 1, 3, T.y ); ret.set( 2, 3, T.z ); ret.set( 3, 3, 1 ); return ret; }
java
{ "resource": "" }
q177642
SpecialEuclideanOps_F64.toHomogeneous
test
public static DMatrixRMaj toHomogeneous( Se2_F64 se, DMatrixRMaj ret ) { if( ret == null ) ret = new DMatrixRMaj( 3, 3 ); else { ret.set( 2, 0, 0 ); ret.set( 2, 1, 0 ); } final double c = se.getCosineYaw(); final double s = se.getSineYaw(); ret.set( 0, 0, c ); ret.set( 0, 1, -s ); ret.set( 1, 0, s ); ret.set( 1, 1, c ); ret.set( 0, 2, se.getX() ); ret.set( 1, 2, se.getY() ); ret.set( 2, 2, 1 ); return ret; }
java
{ "resource": "" }
q177643
SpecialEuclideanOps_F64.axisXyz
test
public static Se3_F64 axisXyz(double dx, double dy, double dz, double rotX, double rotY, double rotZ, Se3_F64 se) { if( se == null ) se = new Se3_F64(); double theta = Math.sqrt(rotX*rotX + rotY+rotY + rotZ*rotZ); if( theta == 0 ) { CommonOps_DDRM.setIdentity(se.R); } else { ConvertRotation3D_F64.rodriguesToMatrix( rotX/theta, rotY/theta, rotZ/theta,theta, se.getR() ); } Vector3D_F64 T = se.getT(); T.x = dx; T.y = dy; T.z = dz; return se; }
java
{ "resource": "" }
q177644
SpecialEuclideanOps_F64.isIdentical
test
public static boolean isIdentical( Se3_F64 a , Se3_F64 b , double tolT , double tolR ) { if( Math.abs(a.T.x-b.T.x) > tolT ) return false; if( Math.abs(a.T.y-b.T.y) > tolT ) return false; if( Math.abs(a.T.z-b.T.z) > tolT ) return false; DMatrixRMaj D = new DMatrixRMaj(3,3); CommonOps_DDRM.multTransA(a.R,b.R,D); Rodrigues_F64 rod = new Rodrigues_F64(); ConvertRotation3D_F64.matrixToRodrigues(D,rod); return rod.theta <= tolR; }
java
{ "resource": "" }
q177645
ConvertCoordinates3D_F64.latlonToUnitVector
test
public static <T extends GeoTuple3D_F64<T>> T latlonToUnitVector(double lat , double lon , T vector ) { if( vector == null ) vector = (T)new Vector3D_F64(); vector.x = Math.cos(lat) * Math.cos(lon); vector.y = Math.cos(lat) * Math.sin(lon); vector.z = -Math.sin(lat); return vector; }
java
{ "resource": "" }
q177646
UtilCircle2D_F64.circle
test
public static boolean circle(Point2D_F64 x0 , Point2D_F64 x1 , Point2D_F64 x2 , Circle2D_F64 circle ) { // points that lie on line a and b double xa = (x0.x+x1.x)/2.0; double ya = (x0.y+x1.y)/2.0; double xb = (x1.x+x2.x)/2.0; double yb = (x1.y+x2.y)/2.0; // slopes of lines a and b double m2 = x0.x-x1.x; double m1 = x1.y-x0.y; double n2 = x2.x-x1.x; double n1 = x1.y-x2.y; // find the intersection of the lines double bottom = m2*n1-n2*m1; if( bottom == 0 ) return false; double alpha = (-m2*(xb-xa) + m1*(yb-ya))/bottom; circle.center.x = xb + n1*alpha; circle.center.y = yb + n2*alpha; circle.radius = circle.center.distance(x0); return true; }
java
{ "resource": "" }
q177647
UtilCircle2D_F64.circleRadiusSq
test
public static double circleRadiusSq(Point2D_F64 x0 , Point2D_F64 x1 , Point2D_F64 x2) { // points that lie on line a and b double xa = (x0.x+x1.x)/2.0; double ya = (x0.y+x1.y)/2.0; double xb = (x1.x+x2.x)/2.0; double yb = (x1.y+x2.y)/2.0; // slopes of lines a and b double m2 = x0.x-x1.x; double m1 = x1.y-x0.y; double n2 = x2.x-x1.x; double n1 = x1.y-x2.y; // find the intersection of the lines double bottom = m2*n1-n2*m1; if( bottom == 0 ) return Double.NaN; double alpha = (-m2*(xb-xa) + m1*(yb-ya))/bottom; double dx = xb + n1*alpha - x0.x; double dy = yb + n2*alpha - x0.y; return dx*dx + dy*dy; }
java
{ "resource": "" }
q177648
ClosestPoint3D_F64.closestPoint
test
public static Point3D_F64 closestPoint(LineParametric3D_F64 l0, LineParametric3D_F64 l1, Point3D_F64 ret) { if( ret == null ) { ret = new Point3D_F64(); } ret.x = l0.p.x - l1.p.x; ret.y = l0.p.y - l1.p.y; ret.z = l0.p.z - l1.p.z; // this solution is from: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline3d/ double dv01v1 = MiscOps.dot( ret, l1.slope ); double dv1v0 = MiscOps.dot( l1.slope, l0.slope ); double dv1v1 = MiscOps.dot( l1.slope, l1.slope ); double t0 = dv01v1 * dv1v0 - MiscOps.dot( ret, l0.slope ) * dv1v1; double bottom = MiscOps.dot( l0.slope, l0.slope ) * dv1v1 - dv1v0 * dv1v0; if( bottom == 0 ) return null; t0 /= bottom; // ( d1343 + mua d4321 ) / d4343 double t1 = ( dv01v1 + t0 * dv1v0 ) / dv1v1; ret.x = (double) 0.5 * ( ( l0.p.x + t0 * l0.slope.x ) + ( l1.p.x + t1 * l1.slope.x ) ); ret.y = (double) 0.5 * ( ( l0.p.y + t0 * l0.slope.y ) + ( l1.p.y + t1 * l1.slope.y ) ); ret.z = (double) 0.5 * ( ( l0.p.z + t0 * l0.slope.z ) + ( l1.p.z + t1 * l1.slope.z ) ); return ret; }
java
{ "resource": "" }
q177649
ClosestPoint3D_F64.closestPoint
test
public static Point3D_F64 closestPoint(LineParametric3D_F64 line, Point3D_F64 pt, Point3D_F64 ret) { if( ret == null ) { ret = new Point3D_F64(); } double dx = pt.x - line.p.x; double dy = pt.y - line.p.y; double dz = pt.z - line.p.z; double n2 = line.slope.normSq(); double d = (line.slope.x*dx + line.slope.y*dy + line.slope.z*dz); ret.x = line.p.x + d * line.slope.x / n2; ret.y = line.p.y + d * line.slope.y / n2; ret.z = line.p.z + d * line.slope.z / n2; return ret; }
java
{ "resource": "" }
q177650
ClosestPoint3D_F64.closestPointOrigin
test
public static Point3D_F64 closestPointOrigin( PlaneGeneral3D_F64 plane , Point3D_F64 found ) { if( found == null ) found = new Point3D_F64(); double n2 = plane.A*plane.A + plane.B*plane.B + plane.C*plane.C; found.x = plane.A*plane.D/n2; found.y = plane.B*plane.D/n2; found.z = plane.C*plane.D/n2; return found; }
java
{ "resource": "" }
q177651
ClosestPoint3D_F64.closestPoint
test
public static Point3D_F64 closestPoint(LineSegment3D_F64 line, Point3D_F64 pt, Point3D_F64 ret) { if( ret == null ) { ret = new Point3D_F64(); } double dx = pt.x - line.a.x; double dy = pt.y - line.a.y; double dz = pt.z - line.a.z; double slope_x = line.b.x - line.a.x; double slope_y = line.b.y - line.a.y; double slope_z = line.b.z - line.a.z; double n = (double) Math.sqrt(slope_x*slope_x + slope_y*slope_y + slope_z*slope_z); double d = (slope_x*dx + slope_y*dy + slope_z*dz) / n; // if it is past the end points just return one of the end points if( d <= 0 ) { ret.set(line.a); } else if( d >= n ) { ret.set(line.b); } else { ret.x = line.a.x + d * slope_x / n; ret.y = line.a.y + d * slope_y / n; ret.z = line.a.z + d * slope_z / n; } return ret; }
java
{ "resource": "" }
q177652
ClosestPoint3D_F64.closestPoint
test
public static Point3D_F64 closestPoint( Point3D_F64 vertexA, Point3D_F64 vertexB, Point3D_F64 vertexC, Point3D_F64 point , Point3D_F64 ret) { if( ret == null ) { ret = new Point3D_F64(); } DistancePointTriangle3D_F64 alg = new DistancePointTriangle3D_F64(); alg.setTriangle(vertexA,vertexB,vertexC); alg.closestPoint(point,ret); return ret; }
java
{ "resource": "" }
q177653
SePointOps_F64.transform
test
public static Point2D_F64 transform( Se2_F64 se, Point2D_F64 orig, Point2D_F64 result ) { if( result == null ) { result = new Point2D_F64(); } final double c = se.getCosineYaw(); final double s = se.getSineYaw(); // copy the values so that no errors happen if orig and result are the same instance double x = orig.x; double y = orig.y; result.x = se.getX() + x * c - y * s; result.y = se.getY() + x * s + y * c; return result; }
java
{ "resource": "" }
q177654
SePointOps_F64.transform
test
public static void transform( Se2_F64 se, Point2D_F64 points[], int length ) { double tranX = se.getX(); double tranY = se.getY(); final double c = se.getCosineYaw(); final double s = se.getSineYaw(); for( int i = 0; i < length; i++ ) { Point2D_F64 pt = points[i]; double x = pt.x; double y = pt.y; pt.x = tranX + x * c - y * s; pt.y = tranY + x * s + y * c; } }
java
{ "resource": "" }
q177655
Quadrilateral_F64.isEquals
test
public boolean isEquals( Quadrilateral_F64 quad , double tol ) { tol *= tol; if( a.distance2(quad.a) > tol ) return false; if( b.distance2(quad.b) > tol ) return false; if( c.distance2(quad.c) > tol ) return false; return d.distance2(quad.d) <= tol; }
java
{ "resource": "" }
q177656
UtilLine2D_F64.acuteAngle
test
public static double acuteAngle( LineGeneral2D_F64 a , LineGeneral2D_F64 b ) { double la = Math.sqrt(a.A*a.A + a.B*a.B); double lb = Math.sqrt(b.A*b.A + b.B*b.B); // numerical round off error can cause it to be barely greater than 1, which is outside the allowed // domain of acos() double value = (a.A*b.A + a.B*b.B)/(la*lb); if( value < -1.0 ) value = -1.0; else if( value > 1.0 ) value = 1.0; return Math.acos(value); }
java
{ "resource": "" }
q177657
UtilLine2D_F64.convert
test
public static LineParametric2D_F64 convert( LinePolar2D_F64 src , LineParametric2D_F64 ret ) { if( ret == null ) ret = new LineParametric2D_F64(); double c = (double) Math.cos(src.angle); double s = (double) Math.sin(src.angle); ret.p.set(c*src.distance,s*src.distance); ret.slope.set(-s,c); return ret; }
java
{ "resource": "" }
q177658
UtilLine2D_F64.convert
test
public static LinePolar2D_F64 convert( LineGeneral2D_F64 src , LinePolar2D_F64 ret ) { if( ret == null ) ret = new LinePolar2D_F64(); double r = Math.sqrt(src.A*src.A + src.B*src.B); double sign = src.C < 0 ? -1 : 1; ret.angle = Math.atan2(-sign*src.B/r,-sign*src.A/r); ret.distance = sign*src.C/r; return ret; }
java
{ "resource": "" }
q177659
UtilLine2D_F64.convert
test
public static LineParametric2D_F64 convert( LineSegment2D_F64 src , LineParametric2D_F64 ret ) { if( ret == null ) ret = new LineParametric2D_F64(); ret.p.set(src.a); ret.slope.set(src.slopeX(),src.slopeY()); return ret; }
java
{ "resource": "" }
q177660
UtilLine2D_F64.convert
test
public static LineGeneral2D_F64 convert( LineSegment2D_F64 src , LineGeneral2D_F64 ret ) { return convert(src.a,src.b,ret); }
java
{ "resource": "" }
q177661
UtilLine2D_F64.convert
test
public static LineGeneral2D_F64 convert( Point2D_F64 a , Point2D_F64 b , LineGeneral2D_F64 ret ) { if( ret == null ) ret = new LineGeneral2D_F64(); ret.A = a.y - b.y; ret.B = b.x - a.x; ret.C = -(ret.A*a.x + ret.B*a.y); return ret; }
java
{ "resource": "" }
q177662
UtilLine2D_F64.convert
test
public static LineParametric2D_F64 convert( Point2D_F64 a , Point2D_F64 b , LineParametric2D_F64 ret ) { if( ret == null ) ret = new LineParametric2D_F64(); ret.p.set(a); ret.slope.x = b.x-a.x; ret.slope.y = b.y-a.y; return ret; }
java
{ "resource": "" }
q177663
UtilLine2D_F64.convert
test
public static LinePolar2D_F64 convert( LineParametric2D_F64 src , LinePolar2D_F64 ret ) { if( ret == null ) ret = new LinePolar2D_F64(); double top = src.slope.y*src.p.x - src.slope.x*src.p.y; ret.distance = top/src.slope.norm(); ret.angle = Math.atan2(-src.slope.x,src.slope.y); if( ret.distance < 0 ) { ret.distance = -ret.distance; ret.angle = UtilAngle.bound(ret.angle + Math.PI); } return ret; }
java
{ "resource": "" }
q177664
UtilLine2D_F64.convert
test
public static LineGeneral2D_F64 convert( LineParametric2D_F64 src , LineGeneral2D_F64 ret ) { if( ret == null ) { ret = new LineGeneral2D_F64(); } ret.A = -src.slope.y; ret.B = src.slope.x; ret.C = -ret.A*src.p.x - ret.B*src.p.y; return ret; }
java
{ "resource": "" }
q177665
UtilLine2D_F64.convert
test
public static LineParametric2D_F64 convert( LineGeneral2D_F64 src , LineParametric2D_F64 ret ) { if( ret == null ) { ret = new LineParametric2D_F64(); } ret.slope.x = src.B; ret.slope.y = -src.A; // find a point on the line if( Math.abs(src.B) > Math.abs(src.A) ) { ret.p.y = -src.C/src.B; ret.p.x = 0; } else { ret.p.x = -src.C/src.A; ret.p.y = 0; } return ret; }
java
{ "resource": "" }
q177666
UtilPlane3D_F64.convert
test
public static PlaneGeneral3D_F64 convert( PlaneNormal3D_F64 input , PlaneGeneral3D_F64 output ) { if( output == null ) output = new PlaneGeneral3D_F64(); Vector3D_F64 n = input.n; Point3D_F64 p = input.p; output.A = n.x; output.B = n.y; output.C = n.z; output.D = n.x*p.x + n.y*p.y + n.z*p.z; return output; }
java
{ "resource": "" }
q177667
UtilPlane3D_F64.convert
test
public static PlaneNormal3D_F64 convert( PlaneTangent3D_F64 input , PlaneNormal3D_F64 output ) { if( output == null ) output = new PlaneNormal3D_F64(); // the value of input is a vector normal to the plane and a point on the plane. output.n.x = input.x; output.n.y = input.y; output.n.z = input.z; output.p.set(input); return output; }
java
{ "resource": "" }
q177668
UtilPlane3D_F64.convert
test
public static PlaneNormal3D_F64 convert( Se3_F64 planeToWorld , PlaneNormal3D_F64 output ) { if( output == null ) output = new PlaneNormal3D_F64(); // the value of input is a vector normal to the plane and a point on the plane. output.n.x = planeToWorld.R.unsafe_get(0,2); output.n.y = planeToWorld.R.unsafe_get(1,2); output.n.z = planeToWorld.R.unsafe_get(2,2); output.p.set(planeToWorld.T.x,planeToWorld.T.y,planeToWorld.T.z); return output; }
java
{ "resource": "" }
q177669
UtilPlane3D_F64.point2Dto3D
test
public static void point2Dto3D(Point3D_F64 origin , Vector3D_F64 axisX , Vector3D_F64 axisY, Point2D_F64 A , Point3D_F64 output ) { output.x = origin.x + axisX.x*A.x + axisY.y*A.y; output.y = origin.y + axisX.y*A.x + axisY.y*A.y; output.z = origin.z + axisX.z*A.x + axisY.y*A.y; }
java
{ "resource": "" }
q177670
UtilPlane3D_F64.planeToWorld
test
public static Se3_F64 planeToWorld( PlaneGeneral3D_F64 plane , Se3_F64 planeToWorld ) { if( planeToWorld == null ) planeToWorld = new Se3_F64(); Vector3D_F64 axisZ = new Vector3D_F64(plane.A,plane.B,plane.C); axisZ.normalize(); Vector3D_F64 axisX = new Vector3D_F64(); Vector3D_F64 axisY = new Vector3D_F64(); UtilPlane3D_F64.selectAxis2D(axisZ,axisX,axisY); return planeToWorld(plane,axisX,axisY,axisZ,planeToWorld); }
java
{ "resource": "" }
q177671
GeoTuple_F64.isIdentical
test
public boolean isIdentical( T t, double tol ) { if( t.getDimension() != getDimension() ) return false; int N = getDimension(); for( int i = 0; i < N; i++ ) { double diff = Math.abs( getIdx( i ) - t.getIdx( i ) ); if( diff > tol ) return false; } return true; }
java
{ "resource": "" }
q177672
GeoTuple_F64.copy
test
@Override public T copy() { T ret = createNewInstance(); int N = getDimension(); for( int i = 0; i < N; i++ ) { ret.setIdx( i, getIdx( i ) ); } return ret; }
java
{ "resource": "" }
q177673
GeoTuple_F64.normSq
test
public double normSq() { double total = 0; int N = getDimension(); for( int i = 0; i < N; i++ ) { double a = getIdx( i ); total += a * a; } return total; }
java
{ "resource": "" }
q177674
UtilLine3D_F64.computeT
test
public static double computeT( LineParametric3D_F64 line , Point3D_F64 pointOnLine ) { double dx = pointOnLine.x - line.p.x; double dy = pointOnLine.y - line.p.y; double dz = pointOnLine.z - line.p.z; double adx = Math.abs(dx); double ady = Math.abs(dy); double adz = Math.abs(dz); double t; if( adx > ady ) { if( adx > adz ) { t = dx/line.slope.x; } else { t = dz/line.slope.z; } } else if( ady > adz ) { t = dy/line.slope.y; } else { t = dz/line.slope.z; } return t; }
java
{ "resource": "" }
q177675
ParabolaGeneral_F64.hasUncountable
test
public boolean hasUncountable() { return UtilEjml.isUncountable(A) || UtilEjml.isUncountable(C) || UtilEjml.isUncountable(D) || UtilEjml.isUncountable(E) || UtilEjml.isUncountable(F); }
java
{ "resource": "" }
q177676
ParabolaGeneral_F64.isEquivalent
test
public boolean isEquivalent( ParabolaGeneral_F64 parabola , double tol ) { double scale = relativeScale(parabola); if( Math.abs(A*scale-parabola.A) > tol ) return false; if( Math.abs(C*scale-parabola.C) > tol ) return false; if( Math.abs(D*scale-parabola.D) > tol ) return false; if( Math.abs(E*scale-parabola.E) > tol ) return false; if( Math.abs(F*scale-parabola.F) > tol ) return false; return true; }
java
{ "resource": "" }
q177677
Box3D_F64.center
test
public Point3D_F64 center( Point3D_F64 storage ) { if( storage == null ) storage = new Point3D_F64(); storage.x = (p0.x + p1.x)/2.0; storage.y = (p0.y + p1.y)/2.0; storage.z = (p0.z + p1.z)/2.0; return storage; }
java
{ "resource": "" }
q177678
UtilLine2D_I32.acuteAngle
test
public static double acuteAngle( LineSegment2D_I32 line0 , LineSegment2D_I32 line1 ) { int dx0 = line0.b.x - line0.a.x; int dy0 = line0.b.y - line0.a.y; int dx1 = line1.b.x - line1.a.x; int dy1 = line1.b.y - line1.a.y; double bottom = Math.sqrt(dx0*dx0 + dy0*dy0) * Math.sqrt(dx1*dx1 + dy1*dy1); return Math.acos((dx0*dx1 + dy0*dy1)/bottom); }
java
{ "resource": "" }
q177679
UtilPoint4D_F64.isInfiniteH
test
public static boolean isInfiniteH(Point4D_F64 p , double tol ) { double n = Math.sqrt(p.x*p.x + p.y*p.y + p.z*p.z); return Math.abs(p.w) <= n*tol; }
java
{ "resource": "" }
q177680
UtilPoint4D_F64.randomN
test
public static List<Point4D_F64> randomN( Point3D_F64 center , double w, double stdev, int num, Random rand ) { List<Point4D_F64> ret = new ArrayList<>(); for( int i = 0; i < num; i++ ) { Point4D_F64 p = new Point4D_F64(); p.x = center.x + rand.nextGaussian() * stdev; p.y = center.y + rand.nextGaussian() * stdev; p.z = center.z + rand.nextGaussian() * stdev; p.w = w; ret.add( p ); } return ret; }
java
{ "resource": "" }
q177681
UtilPoint4D_F64.h_to_e
test
public static Point3D_F64 h_to_e( Point4D_F64 p ) { Point3D_F64 out = new Point3D_F64(); h_to_e(p,out); return out; }
java
{ "resource": "" }
q177682
UtilVector2D_F64.minus
test
public static Vector2D_F64 minus( Point2D_F64 a , Point2D_F64 b , Vector2D_F64 output ) { if( output == null ) output = new Vector2D_F64(); output.x = a.x - b.x; output.y = a.y - b.y; return output; }
java
{ "resource": "" }
q177683
UtilVector2D_F64.identicalSign
test
public static boolean identicalSign( double xa , double ya , double xb , double yb , double tol ) { double dx0 = xb-xa; double dy0 = yb-ya; double dx1 = xb+xa; double dy1 = yb+ya; double error0 = dx0*dx0 + dy0*dy0; double error1 = dx1*dx1 + dy1*dy1; if( error0 < error1 ) { return error0 <= tol*tol; } else { return error1 <= tol*tol; } }
java
{ "resource": "" }
q177684
RectangleLength2D_F64.set
test
public void set(RectangleLength2D_I32 r) { this.x0 = r.x0; this.y0 = r.y0; this.width = r.width; this.height = r.height; }
java
{ "resource": "" }
q177685
UtilEllipse_F64.convert
test
public static EllipseQuadratic_F64 convert( EllipseRotated_F64 input , EllipseQuadratic_F64 output ) { if( output == null ) output = new EllipseQuadratic_F64(); double x0 = input.center.x; double y0 = input.center.y; double a = input.a; double b = input.b; double phi = input.phi; double cphi = Math.cos(phi); double sphi = Math.sin(phi); double cphi2 = cphi*cphi; double sphi2 = sphi*sphi; double a2 = a*a; double b2 = b*b; double x02 = x0*x0; double y02 = y0*y0; // TODO simplfy using more trig identities output.A = cphi2/a2 + sphi2/b2; output.B = sphi*cphi/a2 - sphi*cphi/b2; output.C = sphi2/a2 + cphi2/b2; output.D = -x0*cphi2/a2 - y0*sphi*cphi/a2 - x0*sphi2/b2 + y0*sphi*cphi/b2; output.E = -x0*sphi*cphi/a2 - y0*sphi2/a2 + x0*sphi*cphi/b2 - y0*cphi2/b2; output.F = x02*cphi2/a2 + 2*x0*y0*sphi*cphi/a2 + y02*sphi2/a2 + x02*sphi2/b2 - 2*x0*y0*sphi*cphi/b2 + y02*cphi2/b2 - 1; return output; }
java
{ "resource": "" }
q177686
UtilEllipse_F64.computePoint
test
public static Point2D_F64 computePoint( double t , EllipseRotated_F64 ellipse , Point2D_F64 output ) { if( output == null ) output = new Point2D_F64(); double ct = Math.cos(t); double st = Math.sin(t); double cphi = Math.cos(ellipse.phi); double sphi = Math.sin(ellipse.phi); // coordinate in ellipse frame double x = ellipse.a*ct; double y = ellipse.b*st; // put into global frame output.x = ellipse.center.x + x*cphi - y*sphi; output.y = ellipse.center.y + x*sphi + y*cphi; return output; }
java
{ "resource": "" }
q177687
UtilEllipse_F64.computeAngle
test
public static double computeAngle( Point2D_F64 p , EllipseRotated_F64 ellipse ) { // put point into ellipse's reference frame double ce = Math.cos(ellipse.phi); double se = Math.sin(ellipse.phi); // world into ellipse frame double xc = p.x - ellipse.center.x; double yc = p.y - ellipse.center.y; double x = ce*xc + se*yc; double y = -se*xc + ce*yc; return Math.atan2( y/ellipse.b , x/ellipse.a ); }
java
{ "resource": "" }
q177688
UtilEllipse_F64.computeTangent
test
public static Vector2D_F64 computeTangent( double t , EllipseRotated_F64 ellipse , Vector2D_F64 output ) { if( output == null ) output = new Vector2D_F64(); double ct = Math.cos(t); double st = Math.sin(t); double cphi = Math.cos(ellipse.phi); double sphi = Math.sin(ellipse.phi); // point in ellipse frame multiplied by b^2 and a^2 double x = ellipse.a*ct*ellipse.b*ellipse.b; double y = ellipse.b*st*ellipse.a*ellipse.a; // rotate vector normal into world frame double rx = x*cphi - y*sphi; double ry = x*sphi + y*cphi; // normalize and change into tangent double r = Math.sqrt(rx*rx + ry*ry); output.x = -ry/r; output.y = rx/r; return output; }
java
{ "resource": "" }
q177689
TangentLinesTwoEllipses_F64.selectTangent
test
boolean selectTangent( Point2D_F64 a , Point2D_F64 previousTangent , EllipseRotated_F64 ellipse, Point2D_F64 tangent , boolean cross ) { if( !tangentLines(a,ellipse,temp0,temp1) ) return false; tempLine.a = a; tempLine.b = temp0; boolean crossed0 = Intersection2D_F64.intersection(centerLine,tempLine,junk) != null; tempLine.b = temp1; boolean crossed1 = Intersection2D_F64.intersection(centerLine,tempLine,junk) != null; if( crossed0 == crossed1 ) throw new RuntimeException("Well this didn't work"); if( cross == crossed0 ) { sumDifference += previousTangent.distance2(temp0); tangent.set(temp0); } else { sumDifference += previousTangent.distance2(temp1); tangent.set(temp1); } return true; }
java
{ "resource": "" }
q177690
BoxLength3D_F64.getCorner
test
public Point3D_F64 getCorner(int index , Point3D_F64 corner ) { if( corner == null ) corner = new Point3D_F64(); corner.set(p); if( (index & 0x01) != 0 ) { corner.x += lengthX; } if( (index & 0x02) != 0 ) { corner.y += lengthY; } if( (index & 0x04) != 0 ) { corner.z += lengthZ; } return corner; }
java
{ "resource": "" }
q177691
Distance3D_F64.distance
test
public static double distance( LineParametric3D_F64 l0, LineParametric3D_F64 l1 ) { double x = l0.p.x - l1.p.x; double y = l0.p.y - l1.p.y; double z = l0.p.z - l1.p.z; // this solution is from: http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline3d/ double dv01v1 = MiscOps.dot( x,y,z, l1.slope ); double dv1v0 = MiscOps.dot( l1.slope, l0.slope ); double dv1v1 = MiscOps.dot( l1.slope, l1.slope ); double bottom = MiscOps.dot( l0.slope, l0.slope ) * dv1v1 - dv1v0 * dv1v0; double t0; if( bottom == 0 ) { // handle parallel lines t0 = 0; } else { t0 = (dv01v1 * dv1v0 - MiscOps.dot( x,y,z, l0.slope ) * dv1v1)/bottom; } // ( d1343 + mua d4321 ) / d4343 double t1 = ( dv01v1 + t0 * dv1v0 ) / dv1v1; double dx = ( l0.p.x + t0 * l0.slope.x ) - ( l1.p.x + t1 * l1.slope.x ); double dy = ( l0.p.y + t0 * l0.slope.y ) - ( l1.p.y + t1 * l1.slope.y ); double dz = ( l0.p.z + t0 * l0.slope.z ) - ( l1.p.z + t1 * l1.slope.z ); // round off error can make distanceSq go negative when it is very close to zero double distanceSq = dx * dx + dy * dy + dz * dz; if( distanceSq < 0 ) return 0; else return Math.sqrt( distanceSq ); }
java
{ "resource": "" }
q177692
Distance3D_F64.distance
test
public static double distance( LineParametric3D_F64 l, Point3D_F64 p ) { double x = l.p.x - p.x; double y = l.p.y - p.y; double z = l.p.z - p.z; double cc = x*x + y*y + z*z; // could avoid a square root here by computing b*b directly // however that is most likely more prone to numerical overflow since the numerator will need to be squared // before division can reduce its "power" double b = MiscOps.dot(x,y,z,l.slope)/l.slope.norm(); double distanceSq = cc-b*b; // round off error can make distanceSq go negative when it is very close to zero if( distanceSq < 0 ) { return 0; } else { return Math.sqrt(distanceSq); } }
java
{ "resource": "" }
q177693
Distance3D_F64.distance
test
public static double distance( LineSegment3D_F64 l, Point3D_F64 p ) { double dx = p.x - l.a.x; double dy = p.y - l.a.y; double dz = p.z - l.a.z; double cc = dx*dx + dy*dy + dz*dz; double slope_x = l.b.x - l.a.x; double slope_y = l.b.y - l.a.y; double slope_z = l.b.z - l.a.z; double n = (double) Math.sqrt(slope_x*slope_x + slope_y*slope_y + slope_z*slope_z); double d = (slope_x*dx + slope_y*dy + slope_z*dz) / n; // check end points if( d <= 0 ) return p.distance(l.a); else if( d >= n ) return p.distance(l.b); double distanceSq = cc-d*d; // round off error can make distanceSq go negative when it is very close to zero if( distanceSq < 0 ) { return 0; } else { return Math.sqrt(distanceSq); } }
java
{ "resource": "" }
q177694
Distance3D_F64.distance
test
public static double distance( PlaneGeneral3D_F64 plane , Point3D_F64 point ) { double top = plane.A*point.x + plane.B*point.y + plane.C*point.z - plane.D; return top / Math.sqrt( plane.A*plane.A + plane.B*plane.B + plane.C*plane.C); }
java
{ "resource": "" }
q177695
Distance3D_F64.distance
test
public static double distance( Cylinder3D_F64 cylinder, Point3D_F64 point ) { double r = Distance3D_F64.distance(cylinder.line,point); return r - cylinder.radius; }
java
{ "resource": "" }
q177696
Distance2D_F64.distance
test
public static double distance( LineSegment2D_F64 segmentA , LineSegment2D_F64 segmentB ) { return Math.sqrt(distanceSq(segmentA, segmentB)); }
java
{ "resource": "" }
q177697
Distance2D_F64.distanceSq
test
public static double distanceSq( LineSegment2D_F64 segmentA , LineSegment2D_F64 segmentB ) { // intersection of the two lines relative to A double slopeAX = segmentA.slopeX(); double slopeAY = segmentA.slopeY(); double slopeBX = segmentB.slopeX(); double slopeBY = segmentB.slopeY(); double ta = slopeBX*( segmentA.a.y - segmentB.a.y ) - slopeBY*( segmentA.a.x - segmentB.a.x ); double bottom = slopeBY*slopeAX - slopeAY*slopeBX; // see they intersect if( bottom != 0 ) { // see if the intersection is inside of lineA ta /= bottom; if( ta >= 0 && ta <= 1.0 ) { // see if the intersection is inside of lineB double tb = slopeAX*( segmentB.a.y - segmentA.a.y ) - slopeAY*( segmentB.a.x - segmentA.a.x ); tb /= slopeAY*slopeBX - slopeBY*slopeAX; if( tb >= 0 && tb <= 1.0 ) return 0; } } double closest = Double.MAX_VALUE; closest = Math.min(closest,distanceSq(segmentA, segmentB.a)); closest = Math.min(closest,distanceSq(segmentA, segmentB.b)); closest = Math.min(closest,distanceSq(segmentB, segmentA.a)); closest = Math.min(closest,distanceSq(segmentB, segmentA.b)); return closest; }
java
{ "resource": "" }
q177698
Distance2D_F64.distance
test
public static double distance( Quadrilateral_F64 quad , Point2D_F64 p ) { return Math.sqrt(distanceSq(quad,p)); }
java
{ "resource": "" }
q177699
Distance2D_F64.distanceSq
test
public static double distanceSq( Quadrilateral_F64 quad , Point2D_F64 p ) { LineSegment2D_F64 seg = LineSegment2D_F64.wrap(quad.a, quad.b); double a = distanceSq(seg, p); seg.a = quad.b;seg.b = quad.c; a = Math.min(a,distanceSq(seg,p)); seg.a = quad.c;seg.b = quad.d; a = Math.min(a,distanceSq(seg,p)); seg.a = quad.d;seg.b = quad.a; return Math.min(a, distanceSq(seg, p)); }
java
{ "resource": "" }