|
| 1 | +using UnityEngine; |
| 2 | + |
| 3 | +public class SagittalCoronalAngleConvention : AngleConvention |
| 4 | +{ |
| 5 | + public override string DisplayName => "Coronal/Sagittal"; |
| 6 | + |
| 7 | + public override string XName => "Coronal"; |
| 8 | + |
| 9 | + public override string YName => "Sagittal"; |
| 10 | + |
| 11 | + public override string ZName => "Roll"; |
| 12 | + |
| 13 | + public override bool AllowFrom => false; |
| 14 | + |
| 15 | + public override Vector3 FromConvention(Vector3 conventionAngles) |
| 16 | + { |
| 17 | + |
| 18 | + //conventionAngles = conventionAngles.normalized; |
| 19 | + |
| 20 | + //// Extract the sagittal (XZ) and coronal (YZ) angles from the convention angles |
| 21 | + //float XZAngle = conventionAngles.x; |
| 22 | + //float YZAngle = -conventionAngles.y; // Undo the sign change from ToConvention |
| 23 | + //float combinedRoll = conventionAngles.z; |
| 24 | + |
| 25 | + //Debug.Log(conventionAngles); |
| 26 | + |
| 27 | + ////Convert the angles back to Cartesian coordinates |
| 28 | + //float z = 1f; // We assume unit length for simplicity (same as in ToConvention) |
| 29 | + //float x = Mathf.Tan((90f - XZAngle) * Mathf.Deg2Rad) * z; |
| 30 | + //float y = Mathf.Tan((90f - YZAngle) * Mathf.Deg2Rad) * z; |
| 31 | + |
| 32 | + //Debug.Log((x, y, z)); |
| 33 | + |
| 34 | + //Vector3 pinpointAngles = FromCartesian(new Vector3(x, y, z)); |
| 35 | + |
| 36 | + //Debug.Log(pinpointAngles); |
| 37 | + |
| 38 | + //pinpointAngles.z = combinedRoll - pinpointAngles.x; |
| 39 | + |
| 40 | + |
| 41 | + //Debug.Log(pinpointAngles); |
| 42 | + |
| 43 | + return conventionAngles; |
| 44 | + } |
| 45 | + |
| 46 | + public override Vector3 ToConvention(Vector3 pinpointAngles) |
| 47 | + { |
| 48 | + Vector3 cartesianCoords = ToCartesian(pinpointAngles); |
| 49 | + |
| 50 | + Debug.Log(cartesianCoords); |
| 51 | + |
| 52 | + // Get the XZ angle, which is the sagittal angle |
| 53 | + float XZAngle = 90f - Mathf.Atan2(cartesianCoords.z, cartesianCoords.x) * Mathf.Rad2Deg; |
| 54 | + // Get the YZ angle, which is the coronal plane |
| 55 | + float YZAngle = 90f - Mathf.Atan2(cartesianCoords.z, cartesianCoords.y) * Mathf.Rad2Deg; |
| 56 | + |
| 57 | + Vector3 angles = new Vector3(XZAngle, -YZAngle, pinpointAngles.x + pinpointAngles.z); |
| 58 | + Vector3 back = FromConvention(angles); |
| 59 | + |
| 60 | + Debug.Log((pinpointAngles, back)); |
| 61 | + return new Vector3(XZAngle, -YZAngle, pinpointAngles.x + pinpointAngles.z); |
| 62 | + } |
| 63 | +} |
0 commit comments