georegression.struct.curve.ConicGeneral_F64 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of georegression Show documentation
Show all versions of georegression Show documentation
GeoRegression is a free Java based geometry library for scientific computing in fields such as robotics and computer vision with a focus on 2D/3D space.
The newest version!
/*
* Copyright (C) 2022, Peter Abeles. All Rights Reserved.
*
* This file is part of Geometric Regression Library (GeoRegression).
*
* 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 georegression.struct.curve;
import org.ejml.FancyPrint;
import org.ejml.UtilEjml;
import java.io.Serializable;
/**
* A*x2 + B*x*y + C*y2 + D*x + E*y + F=0
*
* All coefficients are real numbers and A,B,C are all not zero. The discriminant is defined as
* B2 - 4*A*C.
*
* Ellipse: B2 - 4*A*C < 0
* Parabola: B2 - 4*A*C = 0
* Hyperbola: B2 - 4*A*C > 0
*
*
* NOTE: these parameters are unique only up to a scale factor.
*
*
* @author Peter Abeles
*/
public class ConicGeneral_F64 implements Serializable
{
/**
* Coefficients
*/
public double A,B,C,D,E,F;
public ConicGeneral_F64(double a, double b, double c, double d, double e, double f) {
A = a; B = b; C = c;
D = d; E = e; F = f;
}
public ConicGeneral_F64( ConicGeneral_F64 original ) {
setTo(original);
}
public ConicGeneral_F64() {
}
public double evaluate(double x , double y ) {
return A*x*x + B*x*y + C*y*y + D*x + E*y + F;
}
/**
* Returns true if any of its parameters have an uncountable number
*/
public boolean hasUncountable() {
return UtilEjml.isUncountable(A) || UtilEjml.isUncountable(B) || UtilEjml.isUncountable(C)
|| UtilEjml.isUncountable(D) || UtilEjml.isUncountable(E) || UtilEjml.isUncountable(F);
}
public boolean isEllipse( double tol ) {
return B*B+tol < 4*A*C;
}
public boolean isParabola( double tol ) {
return Math.abs(B*B - 4*A*C) <= tol ;
}
public boolean isHyperbola( double tol ) {
return B*B-tol > 4*A*C;
}
public ConicGeneral_F64 setTo(ConicGeneral_F64 original ) {
this.A = original.A;
this.B = original.B;
this.C = original.C;
this.D = original.D;
this.E = original.E;
this.F = original.F;
return this;
}
public ConicGeneral_F64 setTo(double a, double b, double c, double d, double e, double f) {
A = a; B = b; C = c;
D = d; E = e; F = f;
return this;
}
public void zero() {
setTo(0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
}
public ConicGeneral_F64 copy() {
return new ConicGeneral_F64(A,B,C,D,E,F);
}
@Override
public String toString() {
FancyPrint fp = new FancyPrint();
return "ConicGeneral_F64{" +
"A=" + fp.p(A) +
", B=" + fp.p(B) +
", C=" + fp.p(C) +
", D=" + fp.p(D) +
", E=" + fp.p(E) +
", F=" + fp.p(F) +
'}';
}
}