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