Skip to content

Instantly share code, notes, and snippets.

@CosmicPangolin
Created May 26, 2020 22:17
Show Gist options
  • Save CosmicPangolin/4fc98d4af588d6e83f9effe6d29c839a to your computer and use it in GitHub Desktop.
Save CosmicPangolin/4fc98d4af588d6e83f9effe6d29c839a to your computer and use it in GitHub Desktop.
import 'dart:math' as math;
void main() {
double volOf2DHypersphere = volumeOfHypersphere(2, 1000);
}
double volumeOfHypersphere(int dimensions, int simCount) {
int withinCircleCount = 0;
List<List<double>> pointArray = [];
for (int j = 0; j <= simCount; j++) {
List<double> vector= [];
for (int i = 0; i <= dimensions; i++) {
double numBetween0and1 = math.Random().nextDouble();
vector.add(numBetween0and1);
}
pointArray.add(vector);
}
pointArray.forEach((point) {
bool inCircle = false;
// Do your test-in-circle math
if (!inCircle) return;
withinCircleCount++;
});
//Do your compute volume math with circleCount and simCount
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment