one.empty3.library.core.tribase.TubulaireN2 Maven / Gradle / Ivy
Show all versions of empty3-library-generic Show documentation
/*
* Copyright (c) 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.
*/
/*__
* *
* Global license : * GNU GPL v3
*
* author Manuel Dahmen [email protected]_
*
* Creation time 2015-03-25
*
* *
*/
package one.empty3.library.core.tribase;
import one.empty3.library.ColorTexture;
import one.empty3.library.Point3D;
import one.empty3.library.StructureMatrix;
import one.empty3.library.core.nurbs.CourbeParametriquePolynomialeBezier;
import one.empty3.library.core.nurbs.FctXY;
import one.empty3.library.core.nurbs.ParametricCurve;
import one.empty3.library.core.nurbs.ParametricSurface;
import java.awt.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class TubulaireN2 extends ParametricSurface {
public double TAN_FCT_INCR = 0.00000001;
public double NORM_FCT_INCR = 0.00001;
protected StructureMatrix soulCurve = new StructureMatrix<>(0, ParametricCurve.class);
protected StructureMatrix diameterFunction = new StructureMatrix<>(0, FctXY.class);
private Point3D lastTan = null;
public TubulaireN2() {
super();
soulCurve.setElem(new CourbeParametriquePolynomialeBezier());
diameterFunction.setElem(new FctXY());
declareProperties();
}
public TubulaireN2(ParametricCurve curve, double diameter) {
soulCurve.setElem(curve);
soulCurve.getElem().texture(new ColorTexture(Color.BLACK));
FctXY fctXY = new FctXY();
fctXY.setFormulaX("" + diameter);
diameterFunction.setElem(fctXY);
declareProperties();
}
public Point3D calculerNormale(double t) {
Point3D n = calculerTangente(t + NORM_FCT_INCR).moins(calculerTangente(t)).mult(1.0 / NORM_FCT_INCR);
if (n.equals(Point3D.O0)||n.isAnyNaN()) {
int i = 0;
while (i < 3 && (n.equals(Point3D.O0) ||
n.isAnyNaN())) {
n = calculerTangente(t).prodVect(
new Point3D(i == 0 ? 1.0 : 0.0, i == 1 ? 1.0 : 0.0, i == 2 ? 1.0 : 0.0));
i++;
}
}
return n;
}
public Point3D[] calculerAxes(double t, Point3D tangent, int iMin) {
Point3D n = new Point3D(2., 2., 2.);
Point3D axe2;
if (n.norme() != 1.0) {
int i = 0;
while (i < 3 && (n.dot(tangent) != 0.0 ||
n.isAnyNaN() || i= 1.0)
Logger.getAnonymousLogger().log(Level.INFO, "Error in TubulaireN2 vectPerp; px.cross.py.norme!=1");
return vecteurs[j];
}
@Override
public Point3D calculerPoint3D(double u, double v) {
Point3D[] vectPerp = vectPerp(u, v);
return soulCurve.getElem().calculerPoint3D(u).plus(
vectPerp[1].mult(diameterFunction.getElem().result(u) * Math.cos(2 * Math.PI * v))).plus(
vectPerp[2].mult(diameterFunction.getElem().result(u) * Math.sin(2 * Math.PI * v)));
}
/*old
@Override
public Point3D calculerPoint3D(double u, double v) {
Point3D[] vectPerp = vectPerp(u);
return soulCurve.getElem().calculerPoint3D(u).plus(
vectPerp[1].mult(diameterFunction.getElem().result(u) * Math.cos(2 * Math.PI * v))).plus(
vectPerp[2].mult(diameterFunction.getElem().result(u) * Math.sin(2 * Math.PI * v)));
}
*/
@Override
public void declareProperties() {
super.declareProperties();
soulCurve.getElem().declareProperties();
diameterFunction.getElem().declareProperties();
getDeclaredDataStructure().put("soulCurve/Ame de la courbe", soulCurve);
getDeclaredDataStructure().put("diameterFunction/Fonction de positon sur la courbe - diamètre (var='x')", diameterFunction);
}
public StructureMatrix getSoulCurve() {
return soulCurve;
}
public StructureMatrix getDiameterFunction() {
return diameterFunction;
}
public void setSoulCurve(ParametricCurve b) {
this.soulCurve.setElem(b);
}
public void setDiameter(double d) {
FctXY fctXY = new FctXY();
fctXY.setFormulaX("" + d);
this.diameterFunction.setElem(fctXY);
}
}