Creates a Plane object according to the passed floats a, b, c, d and the plane equation : ax + by + cz + d = 0
966534
function Plane(a, b, c, d) {
            this.normal = new Vector3(a, b, c);
            this.d = d;
        }
1248444
static void constructR( DMatrixRMaj R, DMatrixRMaj R_v , DMatrix2x2 R22 ,
							double b1 , double b2 , Vector3D_F64 ca ,
							double sign , DMatrixRMaj tmp )
	{
		tmp.data[0]= R22.a11;
		tmp.data[1]= R22.a12;
		tmp.data[2]= sign*ca.x;

		tmp.data[3]= R22.a21;
		tmp.data[4]= R22.a22;
		tmp.data[5]= sign*ca.y;

		tmp.data[6]= sign*b1;
		tmp.data[7]= sign*b2;
		tmp.data[8]= ca.z;

		CommonOps_DDRM.mult(R_v,tmp,R);
	}
962033
function(t, line$$1) {
                var R = t.determinant ? t.elements : matrix$2.Rotation(t, line$$1.direction).elements;
                var C = line$$1.pointClosestTo(this.anchor).elements;
                var A = this.anchor.elements, N = this.normal.elements;
                var C1 = C[0], C2 = C[1], C3 = C[2], A1 = A[0], A2 = A[1], A3 = A[2];
                var x = A1 - C1, y = A2 - C2, z = A3 - C3;
                return Plane$1.create([
                  C1 + R[0][0] * x + R[0][1] * y + R[0][2] * z,
                  C2 + R[1][0] * x + R[1][1] * y + R[1][2] * z,
                  C3 + R[2][0] * x + R[2][1] * y + R[2][2] * z
                ], [
                  R[0][0] * N[0] + R[0][1] * N[1] + R[0][2] * N[2],
                  R[1][0] * N[0] + R[1][1] * N[1] + R[1][2] * N[2],
                  R[2][0] * N[0] + R[2][1] * N[1] + R[2][2] * N[2]
                ]);
              }
1046841
function(t, obj) {
            	var V, R = null, x, y, z;
            	if (t.determinant) { R = t.elements; }
            	switch (this.elements.length) {
            	case 2:
                        V = obj.elements || obj;
                        if (V.length != 2) { return null; }
                        if (!R) { R = matrix$2.Rotation(t).elements; }
                        x = this.elements[0] - V[0];
                        y = this.elements[1] - V[1];
                        return Vector.create([
            		V[0] + R[0][0] * x + R[0][1] * y,
            		V[1] + R[1][0] * x + R[1][1] * y
                        ]);
                        break;
            	case 3:
                        if (!obj.direction) { return null; }
                        var C = obj.pointClosestTo(this).elements;
                        if (!R) { R = matrix$2.Rotation(t, obj.direction).elements; }
                        x = this.elements[0] - C[0];
                        y = this.elements[1] - C[1];
                        z = this.elements[2] - C[2];
                        return Vector.create([
            		C[0] + R[0][0] * x + R[0][1] * y + R[0][2] * z,
            		C[1] + R[1][0] * x + R[1][1] * y + R[1][2] * z,
            		C[2] + R[2][0] * x + R[2][1] * y + R[2][2] * z
                        ]);
                        break;
            	default:
                        return null;
            	}
                }
212048
function(a, b, c, d) {
            	var elements = [], ni = c, i, nj, j;
            	var rows = this.elements.length, cols = this.elements[0].length;
            	while (ni--) {
            	    i = c - ni - 1;
            	    elements[i] = [];
            	    nj = d;
            	    while (nj--) {
            		j = d - nj - 1;
            		elements[i][j] = this.elements[(a + i - 1) % rows][(b + j - 1) % cols];
            	    }
            	}
            	return Matrix$b.create(elements);
                }
683541
def _create_and_rotate_coordinate_arrays(self, x, y, p):
        

        if p.aspect_ratio == 0 or p.size == 0:
            x = x * 0.0
            y = y * 0.0
        else:
            x = (x*10.0) / (p.size*p.aspect_ratio)
            y = (y*10.0) / p.size

        offset = np.exp(p.size)
        pattern_x = np.add.outer(np.sin(p.orientation)*y, np.cos(p.orientation)*x) + offset
        pattern_y = np.subtract.outer(np.cos(p.orientation)*y, np.sin(p.orientation)*x) + offset

        np.clip(pattern_x, 0, np.Infinity, out=pattern_x)
        np.clip(pattern_y, 0, np.Infinity, out=pattern_y)

        return pattern_x, pattern_y
84752
def Rectangle(p1=(0, 0, 0), p2=(2, 1, 0), c="k", bc="dg", lw=1, alpha=1, texture=None):
    """"""
    p1 = np.array(p1)
    p2 = np.array(p2)
    pos = (p1 + p2) / 2
    length = abs(p2[0] - p1[0])
    height = abs(p2[1] - p1[1])
    return Plane(pos, [0, 0, -1], length, height, c, bc, alpha, texture)
556018
function(plane) {
            if (this.polygons.length === 0) {
                return new CSG();
            }
            // Ideally we would like to do an intersection with a polygon of inifinite size
            // but this is not supported by our implementation. As a workaround, we will create
            // a cube, with one face on the plane, and a size larger enough so that the entire
            // solid fits in the cube.
            // find the max distance of any vertex to the center of the plane:
            var planecenter = plane.normal.times(plane.w);
            var maxdistance = 0;
            this.polygons.map(function(polygon) {
                polygon.vertices.map(function(vertex) {
                    var distance = vertex.pos.distanceToSquared(planecenter);
                    if (distance > maxdistance) maxdistance = distance;
                });
            });
            maxdistance = Math.sqrt(maxdistance);
            maxdistance *= 1.01; // make sure it's really larger
            // Now build a polygon on the plane, at any point farther than maxdistance from the plane center:
            var vertices = [];
            var orthobasis = new CSG.OrthoNormalBasis(plane);
            vertices.push(new CSG.Vertex(orthobasis.to3D(new CSG.Vector2D(maxdistance, -maxdistance))));
            vertices.push(new CSG.Vertex(orthobasis.to3D(new CSG.Vector2D(-maxdistance, -maxdistance))));
            vertices.push(new CSG.Vertex(orthobasis.to3D(new CSG.Vector2D(-maxdistance, maxdistance))));
            vertices.push(new CSG.Vertex(orthobasis.to3D(new CSG.Vector2D(maxdistance, maxdistance))));
            var polygon = new CSG.Polygon(vertices, null, plane.flipped());

            // and extrude the polygon into a cube, backwards of the plane:
            var cube = polygon.extrude(plane.normal.times(-maxdistance));

            // Now we can do the intersection:
            var result = this.intersect(cube);
            result.properties = this.properties; // keep original properties
            return result;
        }
1231843
function() {
            if (this.polygons.length === 0) {
                var m = new CSG.Matrix4x4(); // unity
                return [m,m];
            } else {
                // get a list of unique planes in the CSG:
                var csg = this.canonicalized();
                var planemap = {};
                csg.polygons.map(function(polygon) {
                    planemap[polygon.plane.getTag()] = polygon.plane;
                });
                // try each plane in the CSG and find the plane that, when we align it flat onto z=0,
                // gives the least height in z-direction.
                // If two planes give the same height, pick the plane that originally had a normal closest
                // to [0,0,-1].
                var xvector = new CSG.Vector3D(1, 0, 0);
                var yvector = new CSG.Vector3D(0, 1, 0);
                var zvector = new CSG.Vector3D(0, 0, 1);
                var z0connectorx = new CSG.Connector([0, 0, 0], [0, 0, -1], xvector);
                var z0connectory = new CSG.Connector([0, 0, 0], [0, 0, -1], yvector);
                var isfirst = true;
                var minheight = 0;
                var maxdotz = 0;
                var besttransformation, bestinversetransformation;
                for (var planetag in planemap) {
                    var plane = planemap[planetag];
                    var pointonplane = plane.normal.times(plane.w);
                    var transformation, inversetransformation;
                    // We need a normal vecrtor for the transformation
                    // determine which is more perpendicular to the plane normal: x or y?
                    // we will align this as much as possible to the x or y axis vector
                    var xorthogonality = plane.normal.cross(xvector).length();
                    var yorthogonality = plane.normal.cross(yvector).length();
                    if (xorthogonality > yorthogonality) {
                        // x is better:
                        var planeconnector = new CSG.Connector(pointonplane, plane.normal, xvector);
                        transformation = planeconnector.getTransformationTo(z0connectorx, false, 0);
                        inversetransformation = z0connectorx.getTransformationTo(planeconnector, false, 0);
                    } else {
                        // y is better:
                        var planeconnector = new CSG.Connector(pointonplane, plane.normal, yvector);
                        transformation = planeconnector.getTransformationTo(z0connectory, false, 0);
                        inversetransformation = z0connectory.getTransformationTo(planeconnector, false, 0);
                    }
                    var transformedcsg = csg.transform(transformation);
                    var dotz = -plane.normal.dot(zvector);
                    var bounds = transformedcsg.getBounds();
                    var zheight = bounds[1].z - bounds[0].z;
                    var isbetter = isfirst;
                    if (!isbetter) {
                        if (zheight < minheight) {
                            isbetter = true;
                        } else if (zheight == minheight) {
                            if (dotz > maxdotz) isbetter = true;
                        }
                    }
                    if (isbetter) {
                        // translate the transformation around the z-axis and onto the z plane:
                        var translation = new CSG.Vector3D([-0.5 * (bounds[1].x + bounds[0].x), -0.5 * (bounds[1].y + bounds[0].y), -bounds[0].z]);
                        transformation = transformation.multiply(CSG.Matrix4x4.translation(translation));
                        inversetransformation = CSG.Matrix4x4.translation(translation.negated()).multiply(inversetransformation);
                        minheight = zheight;
                        maxdotz = dotz;
                        besttransformation = transformation;
                        bestinversetransformation = inversetransformation;
                    }
                    isfirst = false;
                }
                return [besttransformation, bestinversetransformation];
            }
        }
1060043
function(t, line) {
    var R = Matrix.Rotation(t, line.direction).elements;
    var C = line.pointClosestTo(this.anchor).elements;
    var A = this.anchor.elements, N = this.normal.elements;
    var C1 = C[0], C2 = C[1], C3 = C[2], A1 = A[0], A2 = A[1], A3 = A[2];
    var x = A1 - C1, y = A2 - C2, z = A3 - C3;
    return Plane.create([
      C1 + R[0][0] * x + R[0][1] * y + R[0][2] * z,
      C2 + R[1][0] * x + R[1][1] * y + R[1][2] * z,
      C3 + R[2][0] * x + R[2][1] * y + R[2][2] * z
    ], [
      R[0][0] * N[0] + R[0][1] * N[1] + R[0][2] * N[2],
      R[1][0] * N[0] + R[1][1] * N[1] + R[1][2] * N[2],
      R[2][0] * N[0] + R[2][1] * N[1] + R[2][2] * N[2]
    ]);
  }
638661
function(a,b,c) {
		var opts = {
			mesh: undefined,
			steps: 12,
			thetaOffset: 0
		};
		if(arguments.length == 1 && typeof arguments[0] == 'object'){ //options object
			for(var prop in arguments[0]){
				opts[prop] = arguments[0][prop];
			}
		} else if(arguments.length == 2){
			opts.steps = arguments[0];
			opts.thetaOffset = arguments[1];
		}
		var cone = new Cone(this.pos,this.getMajorAxis().getVector(), this.radius, this.radius, this.length);
		return cone.toMesh(opts.mesh,opts.steps,opts.thetaOffset,true,true);
	}
1072072
function( ax, ay,
								   bx, by,
								   cx, cy,
								   px, py ) {

		  var aX, aY, bX, bY;
		  var cX, cY, apx, apy;
		  var bpx, bpy, cpx, cpy;
		  var cCROSSap, bCROSScp, aCROSSbp;

		  aX = cx - bx;  aY = cy - by;
		  bX = ax - cx;  bY = ay - cy;
		  cX = bx - ax;  cY = by - ay;
		  apx= px  -ax;  apy= py - ay;
		  bpx= px - bx;  bpy= py - by;
		  cpx= px - cx;  cpy= py - cy;

		  aCROSSbp = aX*bpy - aY*bpx;
		  cCROSSap = cX*apy - cY*apx;
		  bCROSScp = bX*cpy - bY*cpx;

		  return ( (aCROSSbp >= 0.0) && (bCROSScp >= 0.0) && (cCROSSap >= 0.0) );

	}
143273
def _add_sphere(ax):
    
    (u, v) = np.mgrid[0:2 * np.pi:20j, 0:np.pi:10j]
    x = np.cos(u) * np.sin(v)
    y = np.sin(u) * np.sin(v)
    z = np.cos(v)
    ax.plot_wireframe(x, y, z, color='grey', linewidth=0.2)
    return ax
525006
public float sDecept(float y, float A, float B, float C) {
    float tmp, tmp1, tmp2;

    tmp1 = (float) Math.floor(y - A + B) * ((float) 1.0 - C + (A - B) / B) / (A - B);
    tmp2 =
      (float) Math.floor(A + B - y) * ((float) 1.0 - C + ((float) 1.0 - A - B) / B) / ((float) 1.0
        - A - B);

    tmp = Math.abs(y - A) - B;

    return correctTo01((float) 1 + tmp * (tmp1 + tmp2 + (float) 1.0 / B));
  }
595191
public static FloatMatrix axpy(float da, FloatMatrix dx, FloatMatrix dy) {
		//NativeBlas.saxpy(dx.length, da, dx.data, 0, 1, dy.data, 0, 1);
		JavaBlas.raxpy(dx.length, da, dx.data, 0, 1, dy.data, 0, 1);

		return dy;
	}
734755
def draw_plane_wave_3d(ax, beam, dist_to_center=0):
    """"""
    Ex = []; Ey = []; Ez = []

    k = [cos(beam.phi)*sin(beam.theta),
         sin(beam.phi)*sin(beam.theta),
         cos(beam.theta)]
    kx, ky, kz = k

    Nt = 1000
    tstep = 7*pi/4/(Nt-1)

    alpha = beam.alpha
    beta = beam.beta
    phi = beam.phi
    theta = beam.theta
    omega = 1

    for i in range(Nt):
        t = i*tstep

        Ex += [(cos(2*alpha)*cos(phi)*cos(theta) -
                sin(2*alpha)*sin(phi))*cos(omega*t)*cos(2*beta) -
               (cos(phi)*cos(theta)*sin(2*alpha) +
                cos(2*alpha)*sin(phi))*sin(omega*t)*sin(2*beta) -
               dist_to_center*kx]

        Ey += [(cos(2*alpha)*cos(theta)*sin(phi) +
               cos(phi)*sin(2*alpha))*cos(omega*t)*cos(2*beta) -
               (cos(theta)*sin(2*alpha)*sin(phi) -
               cos(2*alpha)*cos(phi))*sin(omega*t)*sin(2*beta) -
               dist_to_center*ky]

        Ez += [-cos(omega*t)*cos(2*alpha)*cos(2*beta)*sin(theta) +
               sin(omega*t)*sin(2*alpha)*sin(2*beta)*sin(theta) -
               dist_to_center*kz]

    ax.plot(Ex, Ey, Ez, beam.color+'-')
    ff = dist_to_center-1.0

    arrx = [-kx*dist_to_center, -kx*ff]
    arry = [-ky*dist_to_center, -ky*ff]
    arrz = [-kz*dist_to_center, -kz*ff]
    arrow = Arrow3D(arrx, arry, arrz, mutation_scale=20,
                    lw=1, arrowstyle="-|>", color=beam.color)
    ax.add_artist(arrow)
    ax.plot([Ex[-1]], [Ey[-1]], [Ez[-1]], '.', markersize=8, color=beam.color)
437185
def makeW(r1, r2, r3, r4=0):
    
    W = np.asarray([
        [r4, r3, -r2, r1],
        [-r3, r4, r1, r2],
        [r2, -r1, r4, r3],
        [-r1, -r2, -r3, r4]])
    return W