one.empty3.testscopy.tests.tests2.balleclou.BalleClous2 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of empty3-library-generic Show documentation
Show all versions of empty3-library-generic Show documentation
3D rendering engine. Plus modeling. Expected glsl textures 3d and 2d rendering
/*
* 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.testscopy.tests.tests2.balleclou;
/*
* 2013 Manuel Dahmen
*/
import one.empty3.library.Point2D;
import one.empty3.library.Point3D;
import one.empty3.library.Sphere;
import java.util.ArrayList;
/*__
* @author Manuel Dahmen
*/
public class BalleClous2 extends Sphere {
private ArrayList points = new ArrayList();
private double d;
public BalleClous2(Point3D c, double r) {
super(c, r);
}
public void addPoint(Point2D p) {
this.points.add(p);
}
public ArrayList points() {
return points;
}
public double formula(Point2D p1, Point2D p2) {
double d = dmaxdist(p1, p2);
return 1 / (d * d + 0.01);
}
public void param(double d) {
this.d = d;
}
public double param() {
return d;
}
public double dmindist(Point2D p0, Point2D p1) {
double[] x = new double[]{-1, 0, 1, -1, 0, 1, -1, 0, 1};
double[] y = new double[]{-1, -1, -1, 0, 0, 0, 1, 1, 1};
double min = 100;
for (int i = 0; i < 9; i++) {
double cur;
cur = Point2D.dist(p0, Point2D.plus(p1, new Point2D(x[i], y[i])));
if (cur < min && cur > 0)
min = cur;
}
return min;
}
public double dmaxdist(Point2D p0, Point2D p1) {
double[] x = new double[]{-1, 0, 1, -1, 0, 1, -1, 0, 1};
double[] y = new double[]{-1, -1, -1, 0, 0, 0, 1, 1, 1};
double max = -1.0;
for (int i = 0; i < 9; i++) {
double cur;
cur = Point2D.dist(p0, Point2D.plus(p1, new Point2D(x[i], y[i])));
if (cur > max)
max = cur;
}
return max;
}
@Override
public Point3D calculerPoint3D(double u, double v) {
Point3D p = super.calculerPoint3D(u, v);
Point2D p0 = new Point2D(u, v);
double mult = 1.0;
for (int i = 0; i < points.size(); i++) {
mult += formula(p0, points.get(i));
}
return getCircle().getCenter().plus(p.moins(getCircle().getCenter()).mult(mult / points.size()).plus(getCircle().getCenter()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy