Fixed Spherical.ToVector3
This commit is contained in:
parent
f8fc9dabe6
commit
ccf0b16136
@ -72,18 +72,22 @@ namespace LinearAlgebra {
|
||||
}
|
||||
|
||||
public readonly Vector3 ToVector3() {
|
||||
float verticalRad = (AngleFloat.deg90 - this.direction.vertical).inRadians;
|
||||
float horizontalRad = this.direction.horizontal.inRadians;
|
||||
float cosVertical = (float)Math.Cos(verticalRad);
|
||||
float sinVertical = (float)Math.Sin(verticalRad);
|
||||
float cosHorizontal = (float)Math.Cos(horizontalRad);
|
||||
float sinHorizontal = (float)Math.Sin(horizontalRad);
|
||||
// float verticalRad = (AngleFloat.deg90 - this.direction.vertical).inRadians;
|
||||
// float horizontalRad = this.direction.horizontal.inRadians;
|
||||
// float cosVertical = (float)Math.Cos(verticalRad);
|
||||
// float sinVertical = (float)Math.Sin(verticalRad);
|
||||
// float cosHorizontal = (float)Math.Cos(horizontalRad);
|
||||
// float sinHorizontal = (float)Math.Sin(horizontalRad);
|
||||
|
||||
float x = this.distance * sinVertical * sinHorizontal;
|
||||
float y = this.distance * cosVertical;
|
||||
float z = this.distance * sinVertical * cosHorizontal;
|
||||
// float x = this.distance * sinVertical * sinHorizontal;
|
||||
// float y = this.distance * cosVertical;
|
||||
// float z = this.distance * sinVertical * cosHorizontal;
|
||||
|
||||
Vector3 v = new(x, y, z);
|
||||
// Vector3 v = new(x, y, z);
|
||||
// return v;
|
||||
|
||||
Vector3 v = this.direction.ToVector3();
|
||||
v *= this.distance;
|
||||
return v;
|
||||
}
|
||||
#else
|
||||
@ -99,22 +103,29 @@ namespace LinearAlgebra {
|
||||
}
|
||||
|
||||
public readonly Vector3Float ToVector3() {
|
||||
float verticalRad = (AngleFloat.deg90 - this.direction.vertical).inRadians;
|
||||
float horizontalRad = this.direction.horizontal.inRadians;
|
||||
float cosVertical = (float)Math.Cos(verticalRad);
|
||||
float sinVertical = (float)Math.Sin(verticalRad);
|
||||
float cosHorizontal = (float)Math.Cos(horizontalRad);
|
||||
float sinHorizontal = (float)Math.Sin(horizontalRad);
|
||||
// float verticalRad = (AngleFloat.deg90 - this.direction.vertical).inRadians;
|
||||
// float horizontalRad = this.direction.horizontal.inRadians;
|
||||
// float cosVertical = (float)Math.Cos(verticalRad);
|
||||
// float sinVertical = (float)Math.Sin(verticalRad);
|
||||
// float cosHorizontal = (float)Math.Cos(horizontalRad);
|
||||
// float sinHorizontal = (float)Math.Sin(horizontalRad);
|
||||
|
||||
float x = this.distance * sinVertical * sinHorizontal;
|
||||
float y = this.distance * cosVertical;
|
||||
float z = this.distance * sinVertical * cosHorizontal;
|
||||
// float x = this.distance * sinVertical * sinHorizontal;
|
||||
// float y = this.distance * cosVertical;
|
||||
// float z = this.distance * sinVertical * cosHorizontal;
|
||||
|
||||
Vector3Float v = new(x, y, z);
|
||||
// Vector3Float v = new(x, y, z);
|
||||
Vector3Float v = this.direction.ToVector3();
|
||||
v *= this.distance;
|
||||
return v;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override readonly string ToString() {
|
||||
return $"Spherical(h: {this.direction.horizontal}, v: {this.direction.vertical}, distance: {this.distance})";
|
||||
}
|
||||
|
||||
|
||||
public readonly float magnitude => this.distance;
|
||||
|
||||
public Spherical normalized {
|
||||
@ -228,7 +239,7 @@ namespace LinearAlgebra {
|
||||
|
||||
return Spherical.Radians(rAvg, azAvgRad, elAvgRad);
|
||||
}
|
||||
|
||||
/*
|
||||
public static Spherical Average(List<Spherical> vectors) {
|
||||
// float sumSinPhiCosTheta = 0.0f;
|
||||
// float sumSinPhiSinTheta = 0.0f;
|
||||
@ -302,9 +313,9 @@ namespace LinearAlgebra {
|
||||
|
||||
return new Spherical(rAvg, new Direction(horizontalAvg, verticalAvg));
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
public static Spherical Average(IEnumerable<Spherical> vectors) {
|
||||
const float EPS = 1e-6f;
|
||||
if (vectors == null) throw new ArgumentNullException(nameof(vectors));
|
||||
@ -371,7 +382,7 @@ namespace LinearAlgebra {
|
||||
|
||||
return Spherical.Radians(rAvgFinal, azAvg, elAvg);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@ -87,27 +87,33 @@ public class Neuroid : Nucleus {
|
||||
float activatedValue = curve.Evaluate(synapseNucleus.outputValue.magnitude);
|
||||
float magnitude = weight * activatedValue;
|
||||
//Debug.Log($"{this.name} {synapseNucleus.outputValue.direction} {synapseNucleus.outputValue.direction.horizontal}{synapseNucleus.outputValue.direction.vertical} {direction}");
|
||||
|
||||
resultVector += direction * magnitude;
|
||||
Vector3 a = direction * magnitude;
|
||||
//Debug.Log($"A {direction} {magnitude} {a}");
|
||||
resultVector += a;
|
||||
}
|
||||
if (average && this.synapses.Count > 0)
|
||||
resultVector /= this.synapses.Count;
|
||||
|
||||
Spherical result = Spherical.FromVector3(resultVector);
|
||||
|
||||
// List<Spherical> vectors = new();
|
||||
// foreach (Synapse synapse in this.synapses) {
|
||||
// if (synapse.nucleus.isSleeping)
|
||||
// continue;
|
||||
List<Spherical> vectors = new();
|
||||
foreach (Synapse synapse in this.synapses) {
|
||||
if (synapse.nucleus.isSleeping)
|
||||
continue;
|
||||
|
||||
// vectors.Add(synapse.nucleus.outputValue);
|
||||
// }
|
||||
// Spherical result2 = Spherical.Average(vectors);
|
||||
// if (average == false)
|
||||
// result2 *= vectors.Count;
|
||||
float weight = synapse.weight;
|
||||
float activatedValue = curve.Evaluate(synapse.nucleus.outputValue.magnitude);
|
||||
float magnitude = weight * activatedValue;
|
||||
Spherical vector = new(magnitude, synapse.nucleus.outputValue.direction);
|
||||
//Debug.Log($"B {synapse.nucleus.outputValue.direction.ToVector3()} {magnitude} {vector.ToVector3()}");
|
||||
vectors.Add(vector); //synapse.nucleus.outputValue);
|
||||
}
|
||||
Spherical result2 = Spherical.Average(vectors);
|
||||
if (average == false)
|
||||
result2 *= vectors.Count;
|
||||
|
||||
// if (result2 != result)
|
||||
// Debug.Log($"update error {result2} != {result}");
|
||||
if (result2 != result)
|
||||
Debug.Log($"update error {result2} != {result}");
|
||||
|
||||
UpdateResult(result);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user