one.empty3.library.P3.new Maven / Gradle / Ivy
Show all versions of empty3-library-3d Show documentation
/*
* This file is part of Empty3.
*
* Empty3 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Empty3 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Empty3. If not, see . 2
*/
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
*/
package one.empty3.library;
import one.empty3.library.core.nurbs.ParametricCurve;
import one.empty3.library.core.nurbs.ParametricSurface;
import java.awt.*;
import java.util.List;
/*__
* *
*
* Classe pour les éléments à trois coordonnées de type Double
* Points, Vecteur 3D et calcul
*
* @author Manuel Dahmen
*/
public class Point3D extends Representable {
public Point3D() {
super();
coordArr.setElem(0d, 0);
coordArr.setElem(0d, 1);
coordArr.setElem(0d, 2);
}/*
public Point3D() {
super();
}*/
/*__
* *
* axe X vector
*/
public static final Point3D X = new Point3D(1d, 0d, 0d);
/*__
* *
* axe Y vector
*/
public static final Point3D Y = new Point3D(0d, 1d, 0d);
/*__
* *
* axe Z vector
*/
public static final Point3D Z = new Point3D(0d, 0d, 1d);
/*__
* *
* O0 origin
*/
public static final Point3D O0 = new Point3D(0d, 0d, 0d);
/*__
* *
* Point "Infinite" limite pour Z-Buffer
*/
public static final Point3D INFINI = new Point3D(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
/*__
* *
* Coordonnées (coordArr,y,z) du point
*/
StructureMatrix coordArr = new StructureMatrix<>(1, Double.class);
/*__
* *
* Pour le tracé de surface normale au point
*/
protected Point3D normale;
/*__
* *
* id
*/
/*__
* *
* Constructeur Point Origine
*/
/*__
* *
*
* @param x0 coordArr-coordonnée
* @param y0 y-coordonnée
* @param z0 z-coordonnée
*/
public Point3D(Double x0, Double y0, Double z0) {
super();
coordArr.setElem(x0, 0);
coordArr.setElem(y0, 1);
coordArr.setElem(z0, 2);
}
/*__
* *
*
* @param x0 coordArr-coordonnée
* @param y0 y-coordonnée
* @param z0 z-coordonnée
*/
public Point3D(Double x0, Double y0, Double z0, ITexture t) {
this(x0, y0, z0);
texture(t);
}
/*__
* *
* Initialise à partir d'un vecteur
*
* @param x0 coordonnées (>3)
*/
public Point3D(Double... x0) {
int i=0;
for(Double d : x0) {
coordArr.setElem(d,i);
i++;
}
}
public Point3D(Double[] x0, ITexture t) {
int i=0;
for(Double d : x0) {
coordArr.setElem(d,i);
i++;
}
texture(t);
}
/*__
*
*
* @param p0 point à copier
*/
public Point3D(Point3D p0) {
super();
for(int i=0; i coordArr) {
this(coordArr.getElem(0), coordArr.getElem(1), coordArr.getElem(2));
}
public static Point3D n(Double a, Double b, Double c) {
return new Point3D(a, b, c);
}
/*__
* *
* Distance cartésienne entre 2 points
*
* @param p1 Point1
* @param p2 Point2
* @return
*/
public static Double distance(Point3D p1, Point3D p2) {
double d = 0.0;
for(int i=0; i=0 && i<3 && coordArr.data1d.size()==3)
return coordArr.getElem(i);
/* else
try {
throw new Throwable("point3D coordArr out of bounds or array dim error\nValues="+coordArr.toString()+"\nSize="+coordArr.data1d.size());
} catch (Throwable throwable) {
throwable.printStackTrace();
}
return Double.NaN;*/
}
public Point3D scale() {
if(scale==null)
{
return Point3D.n(1.,1.,1.);
}
return new Point3D (get(0)*scale.get(1),get(1)*scale.get(1),get(2)*scale.get(2));
}
public List getDoubleArray() {
return coordArr.getData1d();
}
public Point3D getNormale() {
return normale;
}
public void setNormale(Point3D normale) {
this.normale = normale;
}
public Double getY() {
return coordArr.getElem(1);
}
public void setY(Double x0) {
coordArr.setElem(x0, 1);
}
public Double getZ() {
return coordArr.getElem(2);
}
public void setZ(Double x0) {
coordArr.setElem(x0, 2);
}
public Double getX() {
return coordArr.getElem(0);
}
public void setX(Double x0) {
coordArr.setElem(x0, 0);
}
public Point3D plus(Point3D p){
Point3D p1 = new Point3D(this);
for(int i=0;i getCoordArr() {
return coordArr;
}
public void setCoordArr(StructureMatrix coordArr) {
this.coordArr = coordArr;
}
public Point3D calculerPoint0dT(double t) {
return this;
}
/*
public Point3D statOp(Point3D p, char po, int length){
switch(po) {
case '+':
for(int i=0; i<3; i++)
coordArr.setElem(i,coordArr.getElem(i)+p.get(i));
break;
case '-':
for(int i=0; i<3; i++)
coordArr.setElem( coordArr.getElem(i)-p.get(i));
break;
case '*':
for(int i=0; i<3; i++)
coordArr.setElem( i, coordArr.getElem(i)*p.get(i));
break;
case '/':
for(int i=0; i<3; i++)
coordArr.setElem(i,
coordArr.getElem(i)/p.get(i));
break;
case '.':
double sum = 0.0;
for(int i=0; i<3; i++)
sum += coordArr.getElem(i)*p.get(i);
coordArr.setElem(0, sum);
break;
}
return this;
}*/
}