Examples of GVector


Examples of javax.vecmath.GVector

     */
    public static GVector mapRows(Function fun, GMatrix points) {
        if (fun == nullthrow new NullPointerException("fun");       
        int rows = points.getNumRow();
        int cols = points.getNumCol();
        GVector values = new GVector(rows);
       
        for(int i = 0; i < rows; i++) {
            GVector x = new GVector(cols);
            points.getRow(i, x);
            values.setElement(i, fun.eval(x));
        }
       
        return values;
View Full Code Here

Examples of javax.vecmath.GVector

    /**
     * Returns a vector of the given size where each element is randomly
     * chosen from a uniform distribution on the interval [0, 1].
     */
    public static GVector randomUniformVector(int size) {
        GVector v = new GVector(size);
        for(int i = 0; i < size; i++) {
            v.setElement(i, RAND.nextDouble());
        }
        return v;
    }
View Full Code Here

Examples of javax.vecmath.GVector

     * Returns a vector of the given size where each element is randomly
     * chosen from a Gaussian ("normal") distribution with mean 0.0 and
     * standard deviation 1.0.
     */
    public static GVector randomGaussianVector(int size) {
        GVector v = new GVector(size);
        for(int i = 0; i < size; i++) {
            v.setElement(i, RAND.nextGaussian());
        }
        return v;
    }
View Full Code Here

Examples of javax.vecmath.GVector

  {
    int n = 4;
    int m = 2;

    GMatrix data = new GMatrix(m, n);
    GVector values = new GVector(n);

    for (int i = 0; i < m; i++)
    {
      data.setRow(i, getRandomArray(n));
    }

    double[] v = new double[n];
    for (int i = 0; i < n; i++)
    {
      double[] col = new double[m];
      data.getColumn(i, col);
      v[i] = getValue(col);
    }

    values.set(v);


    System.out.println("data = " + data);
    System.out.println("values = " + values);


    Kernel kernel = new PolynomialKernel(m);
//    Kernel kernel = LinearKernel.KERNEL;

    double lambda = 0.5;

    Representer representer = Regression.solve(data, values, kernel, lambda);

    GVector gv = representer.coeffs();
    double dd = representer.eval(new GVector(new double[]{2, 3}));
    System.out.println("dd = " + dd);
    System.out.println(gv);


  }
View Full Code Here

Examples of javax.vecmath.GVector

   * @return
   */
  public Float intersectsWithRay(Coordinate origin, Coordinate direction)
  {
    float largestDistance = Math.max((float)(A.getPosition().x - origin.x), (float)(B.getPosition().x - origin.x)) * 2f;
    GVector v=new GVector(new double[] {origin.x,origin.y});
    GVector d=new GVector(new double[] {direction.x,direction.y});
    d.scale(largestDistance);
    v.add(d);
    LineSegment raySegment = new LineSegment(new Vertex(origin, 0), new Vertex(new Coordinate(v.getElement(0),v.getElement(1)), 0));
    Coordinate intersection= findIntersection(this, raySegment);
    Float value = null;
   
    if (intersection != null) {
      v=new GVector(new double[] {origin.x,origin.y});
      v.sub(new GVector(new double[] {intersection.x,intersection.y}));
      double dist=v.norm();
      value = new Float(dist);
    }

    return value;
View Full Code Here

Examples of javax.vecmath.GVector

    double ua = uaNum / denom;
    double ub = ubNum / denom;

    if (clamp(ua, 0f, 1f) != ua || clamp(ub, 0f, 1f) != ub)
      return null;
    GVector v=new GVector(new double[] {a.A.getPosition().x,a.A.getPosition().y});
    GVector d=new GVector(new double[] {a.B.getPosition().x,a.B.getPosition().y});
    d.sub(v);
    d.scale(ua);
    d.add(v);
    return new Coordinate(d.getElement(0),d.getElement(1));   
  }
View Full Code Here

Examples of javax.vecmath.GVector

      return shapeVerts;

    //otherwise we can find our mutually visible vertex to split the polygon
   
    Coordinate I = rightMostHoleVertex.getPosition();
    GVector i=new GVector(new double[] {I.x,I.y});
    i.add(new GVector(new double[] {closestPoint.floatValue(),0.0}));
   
    Vertex P = (closestSegment.A.getPosition().x > closestSegment.B.getPosition().x)
      ? closestSegment.A
      : closestSegment.B;
   
    //construct triangle MIP
    Triangle mip = new Triangle(rightMostHoleVertex, new Vertex(I, 1), P);
    //see if any of the reflex vertices lie inside of the MIP triangle
    ArrayList interiorReflexVertices = new ArrayList();
    for (int count=0;count<reflexVertices.size();count++) {
      Vertex v=(Vertex)reflexVertices.get(count);
      if (mip.ContainsPoint(v))
        interiorReflexVertices.add(v);
    }
   
    //if there are any interior reflex vertices, find the one that, when connected
    //to our rightMostHoleVertex, forms the line closest to Vector2.UnitX
    if (interiorReflexVertices.size() > 0)
    {
      float closestDot = -1f;
      for (int count=0;count<interiorReflexVertices.size();count++)
      {
        Vertex v=(Vertex)interiorReflexVertices.get(count);
        GVector n=new GVector(new double[] {v.getPosition().x,v.getPosition().y});
        n.sub(new GVector(new double[] {rightMostHoleVertex.getPosition().x,rightMostHoleVertex.getPosition().y}));
        n.normalize();
        GVector m=new GVector(new double[] {1.0,0.0});
        float dot=(float)m.dot(n);
       

        //if this line is the closest we've found
        if (dot > closestDot)
        {
View Full Code Here

Examples of javax.vecmath.GVector

    Vertex p = (Vertex)polygonVertices.get(polygonVertices.indexOf(c) - 1);
    Vertex n = (Vertex)polygonVertices.get(polygonVertices.indexOf(c) + 1);
    Coordinate cc=c.getPosition();
    Coordinate pc=p.getPosition();
    Coordinate nc=n.getPosition();
    GVector d1=new GVector(new double[] {cc.x,cc.y});
    d1.sub(new GVector(new double[] {pc.x,pc.y}));
    d1.normalize();
   
    GVector d2=new GVector(new double[] {nc.x,nc.y});
    d2.sub(new GVector(new double[] {cc.x,cc.y}));
    d2.normalize();
   
   
    GVector n2=new GVector(new double[] {-d2.getElement(1),d2.getElement(0)});
    return d1.dot(n2)<=0.0;
  }
View Full Code Here

Examples of javax.vecmath.GVector

    for (int i = 1; i < vertices.getNumPoints(); i++)
    {
      Coordinate p2 = vertices.getCoordinateN(i);
      Coordinate p3 = vertices.getCoordinateN((i + 1) % vertices.getNumPoints());
      GVector e1=new GVector(new double[] {p1.x,p1.y});
      e1.sub(new GVector(new double[] {p2.x,p2.y}));
      GVector e2=new GVector(new double[] {p3.x,p3.y});
      e2.sub(new GVector(new double[] {p2.x,p2.y}));
     

      if (e1.getElement(0)* e2.getElement(1) - e1.getElement(1) * e2.getElement(0) >= 0)
        clockWiseCount++;
      else
        counterClockWiseCount++;

      p1 = p2;
View Full Code Here

Examples of toxi.geom.GVector

                int span = uKnots.findSpan(uk[i]);
                double[] tmp = uKnots.basisFunctions(span, uk[i]);
                System.arraycopy(tmp, 0, A, i * n + span - degree, tmp.length);
            }
            final GMatrix a = new GMatrix(n, n, A);
            final GVector perm = new GVector(n);
            final GMatrix lu = new GMatrix(n, n);
            a.computeLUD(lu, perm);

            final Vec4D[] cps = new Vec4D[n];
            for (int i = 0; i < cps.length; i++) {
                cps[i] = new Vec4D(0, 0, 0, 1);
            }

            // x-ccordinate
            final GVector b = new GVector(n);
            for (int j = 0; j < n; j++) {
                b.setElement(j, points[j].x);
            }
            final GVector sol = new GVector(n);
            sol.backSolveLUD(lu, b, perm);
            for (int j = 0; j < n; j++) {
                cps[j].x = (float) sol.get(j);
            }

            // y-ccordinate
            for (int j = 0; j < n; j++) {
                b.setElement(j, points[j].y);
            }
            sol.zero();
            sol.backSolveLUD(lu, b, perm);
            for (int j = 0; j < n; j++) {
                cps[j].y = (float) sol.get(j);
            }

            // z-ccordinate
            for (int j = 0; j < n; j++) {
                b.setElement(j, points[j].z);
            }
            sol.zero();
            sol.backSolveLUD(lu, b, perm);
            for (int j = 0; j < n; j++) {
                cps[j].z = (float) sol.get(j);
            }
            return new BasicNurbsCurve(cps, uKnots);
        } catch (SingularMatrixException ex) {
            throw new InterpolationException(ex);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.