Array Physics2DDirectSpaceState::_intersect_point(const Vector2 &p_point, int p_max_results, const Vector<RID> &p_exclude, uint32_t p_layers, uint32_t p_object_type_mask) { Set<RID> exclude; for (int i = 0; i < p_exclude.size(); i++) exclude.insert(p_exclude[i]); Vector<ShapeResult> ret; ret.resize(p_max_results); int rc = intersect_point(p_point, ret.ptr(), ret.size(), exclude, p_layers, p_object_type_mask); if (rc == 0) return Array(); Array r; r.resize(rc); for (int i = 0; i < rc; i++) { Dictionary d; d["rid"] = ret[i].rid; d["collider_id"] = ret[i].collider_id; d["collider"] = ret[i].collider; d["shape"] = ret[i].shape; d["metadata"] = ret[i].metadata; r[i] = d; } return r; }
std::vector<double> PointOfSurfaceIntersect(std::vector<double> point1, std::vector<double> point2, std::map<unsigned, double> surface) { std::vector<double> intersect_point(point1.size() - surface.size()); bool cross_surface = false; unsigned count_cross = 0; for(auto& variable: surface) if(point1[variable.first] > variable.second) if(point2[variable.first] < variable.second) ++count_cross; if(count_cross == surface.size()) cross_surface = true; return intersect_point; }
float intersect_circle(t_ray *ray, t_circle *circle) { float a; float b; float c; float delta; a = ray->d.x * ray->d.x + ray->d.y * ray->d.y + ray->d.z * ray->d.z; b = 2 * (ray->d.x * (ray->o.x - circle->center.x) + ray->d.y * (ray->o.y - circle->center.y) + ray->d.z * (ray->o.z - circle->center.z)); c = ((ray->o.x - circle->center.x) * (ray->o.x - circle->center.x) + (ray->o.y - circle->center.y) * (ray->o.y - circle->center.y) + (ray->o.z - circle->center.z) * (ray->o.z - circle->center.z)) - circle->r * circle->r; delta = b * b - 4 * a * c; if (delta < 0) return (-1); else return (intersect_point(a, b, delta)); }