I’m trying to replicate a line line intersection algorithm whilst putting my own spin on it. Heres the code in Javascript from (Coding Math - youtube channel) ----- Amazing channel do check it out if you have time!!!
Now being new to processing i’m not sure if this is the best way of implementing this feature. I have opted for a Hashmap option which stores the x and y like this;
HashMap<String, Float> check_intersect(Line a, Line b){
//for(int i=0;i<this.sorted_lines.size();i++){
float a1 = a.y2 - a.y1;
float b1 = a.x1 - a.x2;
float c1 = a1 * a.x1 + b1 * a.y1;
float a2 = b.y2 - b.y1;
float b2 = b.x1 - b.x2;
float c2 = a2 * b.x1 + b2 * b.y1;
float denom = a1 * b1 - b2 * b1;
//float x = (b2 *c1 - b1 * c2) / denom;
//float y = (a1 *c2 - a2 * c1) / denom;
HashMap<String, Float> p = new HashMap<String, Float>();
Float x = (b2 *c1 - b1 * c2) / denom;
Float y = (a1 *c2 - a2 * c1) / denom;
//p.put("x", x);
p.put("x",x);
p.put("y",y);
return p;
}
Just wanted to check if this way has any drawbacks that people know of (again very new to processing);
Thanks in advance.