All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.empty3.feature.CourbeN11 Maven / Gradle / Ivy

There is a newer version: 2024.5.10
Show newest version
/*
 * Copyright (c) 2022-2023. Manuel Daniel Dahmen
 *
 *
 *    Copyright 2012-2023 Manuel Daniel Dahmen
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package one.empty3.feature;

import one.empty3.library.Point3D;
import one.empty3.library.StructureMatrix;
import one.empty3.library.core.nurbs.CourbeParametriquePolynomialeBezier;

public class CourbeN11 extends CourbeParametriquePolynomialeBezier {
    private StructureMatrix pointsCount = new StructureMatrix<>(0, Integer.class);
    private StructureMatrix closed = new StructureMatrix<>(0, Boolean.class);

    {
        pointsCount.setElem(20);
    }

    int INCR_SUBCURVE = 10;

    public CourbeN11(Point3D[] point3DS) {
        super(point3DS);
        closed.setElem(false);
    }

    public CourbeN11() {
        super();
        closed.setElem(false);
    }

    @Override
    public void declareProperties() {
        super.declareProperties();
        getDeclaredDataStructure().put("pointsCount/Nombre de points intermédiaires div 2", pointsCount);
        getDeclaredDataStructure().put("closed/Courbe fermee ou ouverte", closed);
    }

    @Override
    public Point3D calculerPoint3D(double t) {
        int size = coefficients.getData1d().size();
        double t2 = t;
        return calculerPoint3D(t2, (int) (t2 * size));
    }

    public Point3D calculerPoint3D_N(double t) {
        int N = 0;
        int size = coefficients.getData1d().size();
        Point3D sum = Point3D.O0;
        for (int j = -N; j <= N; j++) {
            double t2 = t + (1.0 / size) * (j);
            sum = sum.plus(calculerPoint3D(t2, (int) (t2 * size)));
        }
        return sum.mult(1. / (N * 2 + 1));
    }

    public Point3D calculerPoint3D(double t, int i) {
        if (closed.getElem())
            return calculerPoint3DClosedCurve(t, i);
        Point3D sum = new Point3D();
        int N = coefficients.getData1d().size();
        int start = Math.max(0, i - pointsCount.getElem());
        int end = Math.min(N, i + pointsCount.getElem());
        int n = end - start;
        double tFract = (t * N - (int) (t * N)); // tFract := t mod N
        if (getIncrU().getElem() != 1. / n / INCR_SUBCURVE)
            setIncrU(1. / n / INCR_SUBCURVE);
        for (i = start; i < end; i++) {
            sum = sum.plus(coefficients.getElem(i).mult(B(i - start, n - 1, tFract)));
        }
        return sum;
    }

    public Point3D calculerPoint3DClosedCurve(double t, int i) {
        Point3D sum = new Point3D();
        int N = coefficients.getData1d().size();
        int start = i - pointsCount.getElem();
        int end = Math.min(N, i + pointsCount.getElem());
        int n = end - start;
        int i0 = start;
        int i1 = end;
        if (start < 0) start = N + start;
        if (end > N - 1) end = end % (N);
        double tFract = (t * N - (int) (t * N)); // tFract := t mod N
        if (getIncrU().getElem() != 1. / n / INCR_SUBCURVE)
            setIncrU(1. / n / INCR_SUBCURVE);
        for (i = 0; i < n; i++) {
            int idxArr = (N + start + i) % N;
            sum = sum.plus(coefficients.getElem((N + idxArr) % N).mult(B(i, n - 1, tFract)));
        }
        return sum;
    }

    public StructureMatrix getPointsCount() {
        return pointsCount;
    }

    public void setPointsCount(StructureMatrix pointsCount) {
        this.pointsCount = pointsCount;
    }

    public StructureMatrix getClosed() {
        return closed;
    }

    public void setClosed(StructureMatrix closed) {
        this.closed = closed;
    }

    public int getINCR_SUBCURVE() {
        return INCR_SUBCURVE;
    }

    public void setINCR_SUBCURVE(int INCR_SUBCURVE) {
        this.INCR_SUBCURVE = INCR_SUBCURVE;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy