Porting over Ray-Tracing-2 to Intellij. Fixed processing core reference issues. still need to fix other issues though.

This commit is contained in:
Quinn
2023-04-05 22:45:50 -05:00
parent b280f0e98d
commit c17ee2e960
4 changed files with 349 additions and 0 deletions

69
src/SLAM.java Normal file
View File

@@ -0,0 +1,69 @@
import processing.core.*;
import java.util.ArrayList;
public class SLAM{
ArrayList<PVector> points = new ArrayList<PVector>();
SLAM(){
}
public void addPoints(ArrayList<PVector> newPoints){
Line line = new Line(newPoints);
}
}
class Line{
PVector direction = new PVector(0,0);
PVector position = new PVector(0,0);
Line(){}
Line(PVector direction, PVector position){
this.direction = direction;
this.position = position;
}
/**
* @brief attempt to find the line of best fit for the given points
* @param points the points to get the line of best for
*/
Line(ArrayList<PVector> points){
bestFit(points);
}
// least squares line of best fit algorithm
private void bestFit(ArrayList<PVector> points){
// get the mean of all the points
PVector mean = new PVector();
for(PVector point : points){
mean.add(point);
}
mean.div(points.size())
// this section calculates the direction vector of the line of best fit
PVector direction = new PVector();
// get the rise and run of the line of best fit
for(PVector point : points){
direction.y += (point.x - mean.x)*(point.y - mean.y); // rise
direction.x += pow((point.x - mean.x),2);
}
this.position = mean;
this.direction = direciton;
}
public PVector getSlopeIntForm(){
float slope = direction.y / direction.x;
float intercept = position.y - slope * position.x;
return new PVector(slope, intercept);
}
public PVector getDirection(){
return direction;
}
public PVector getPosition(){
return position;
}
}