我正在将Apache Commons Math和Lemmingapex Trilateration导入为Processing中的外部jar库。我遵循了SO的指示:
How to add external libraries in processing
处理草图似乎工作正常但我每次运行草图时都会将以下错误打印到控制台。
No library found for org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer
这是Processing PDE Sketch:
import org.apache.commons.math3.fitting.leastsquares.*;
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum;
import org.apache.commons.math3.linear.RealMatrix;
import org.apache.commons.math3.linear.RealVector;
import com.lemmingapex.trilateration.*;
void setup() {
size(1024, 768);
double[][] positions = new double[][] { { 8.0, 12.0 }, { 15.0, 40.0 }, { 40.0, 20.0 }, { 22, 40 } };
double[] distances = new double[] { 10.06, 13.97, 23.32, 10.31 };
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();
// the answer
double[] centroid = optimum.getPoint().toArray();
printArray(centroid);
// error and geometry information; may throw SingularMatrixException depending the threshold argument provided
RealVector standardDeviation = optimum.getSigma(0);
RealMatrix covarianceMatrix = optimum.getCovariances(0);
printArray(standardDeviation);
printArray(covarianceMatrix);
background(37);
ellipse((float) centroid[0], (float) centroid[1], 20, 20);
}
void draw() {
}
我哪里错了?有什么指针吗?
答案 0 :(得分:0)
您是否在链接到的答案上看到了my comment?
在Processing中使用库的最简单方法是将库的.jar
文件拖到Processing编辑器中。只需为您需要的所有.jar
文件执行此操作即可。 (您可能必须先删除已创建的库目录。)
无耻的自我推销:我写了一篇关于在处理可用的here中使用库的教程。
答案 1 :(得分:0)
我能够使用以下导入使其工作。
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum;
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer;
import com.lemmingapex.trilateration.NonLinearLeastSquaresSolver;
import com.lemmingapex.trilateration.TrilaterationFunction;
import com.lemmingapex.trilateration.*;
谢谢凯文。希望这有助于其他人。