You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
2.1 KiB
58 lines
2.1 KiB
using System;
|
|
using Pores.Interfaces;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Pores.Models.Localizations
|
|
{
|
|
public class NormalLocalization : BaseLocalization
|
|
{
|
|
public double mu { get; set; }
|
|
public double sigma { get; set; }
|
|
public double maxR { get; set; }
|
|
private Material Material { get; }
|
|
|
|
public double GaussFunction (double x, double sigma, double mu)
|
|
{
|
|
double part1 = 1.0/ (sigma * Math.Sqrt(2 * 3.14));
|
|
double part2 = Math.Exp(-Math.Pow(x - mu, 2) / (2.0 * Math.Pow(sigma, 2)));
|
|
return part1 * part2;
|
|
}
|
|
|
|
public double GaussFunctionByHeight (Coordinate c)
|
|
{
|
|
return GaussFunction(c.Z, sigma, mu);
|
|
}
|
|
|
|
public override ObservableCollection<Pore> GetLocalization()
|
|
{
|
|
var r = new Random();
|
|
maxR = Math.Sqrt(Material.NumberOfPores / (Material.Height * Material.Width * Material.Depth) / 3.14);
|
|
var result = new ObservableCollection<Pore>();
|
|
for (int i = 0; i <= Material.NumberOfPores; i++)
|
|
for (int j = 0; j <= Material.NumberOfPores; j++)
|
|
for (int k = 0; k <= Material.NumberOfPores; k++)
|
|
{
|
|
var c = new Coordinate()
|
|
{
|
|
X = (double) i / Material.NumberOfPores * Material.Width,
|
|
Y = (double) j / Material.NumberOfPores * Material.Depth,
|
|
Z = (double) k / Material.NumberOfPores * Material.Height,
|
|
};
|
|
var randomDouble = r.NextDouble();
|
|
var gaussResult = GaussFunctionByHeight(c);
|
|
if (randomDouble < gaussResult)
|
|
result.Add(new Pore() { Point = c, Radius = maxR });
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public NormalLocalization(Material material)
|
|
{
|
|
Material = material;
|
|
sigma = 4;
|
|
mu = Material.Height - Material.Height / 4;
|
|
|
|
}
|
|
}
|
|
}
|
|
|