Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Newtonsoft.Json;
using REST_JSON_API;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;
/// <summary>
/// Point in 3D Space
/// </summary>
public class PyramidFact : FactWrappedCRTP<PyramidFact>
{
//used points
public string PidR, PidD;
public Vector3 A, B, C, M, D, D_offset;
public float ab;
public float bc;
public float Volume = 0.0F;
public RectangleFact GetR {get => (RectangleFact)FactRecorder.AllFacts[PidR];}
public PointFact GetD {get => (PointFact)FactRecorder.AllFacts[PidD];}
protected void calculate_vectors(){
A = GetR.A + Vector3.zero;
B = GetR.B + Vector3.zero;
C = GetR.C + Vector3.zero;
D = GetD.Point + Vector3.zero;
D_offset = Quaternion.AngleAxis(-90, Vector3.right) * (D - B);
/*
Vector3 d_AB = A + Vector3.Project(D - A, B - A);
Vector3 d_BC = B + Vector3.Project(D - B, C - B);
abPosition = Vector3.Distance(B, d_AB) / Vector3.Distance(B, A);
bcPosition = Vector3.Distance(B, d_BC) / Vector3.Distance(B, C);
*/
ab = (B - A).magnitude;
bc = (C - B).magnitude;
M = Vector3.ProjectOnPlane(D, Vector3.Cross(A - B, C - B));
Volume = 1/3 * GetR.Area * Vector3.Distance(M, D);
Vector3 forward = Vector3.Cross((C - B), (A - B));
Vector3 up = A - B;
if ((A - B).y < 0)
{
up = -up;
}
Rotation = Quaternion.LookRotation(forward, up);
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
}
public PyramidFact() : base(){
this.PidR = null;
this.PidD = null;
}
[JsonConstructor]
public PyramidFact( string PidT, string PidD) : base()
{
this.PidR = PidT;
this.PidD = PidD;
calculate_vectors();
}
/// <summary>
/// Bypasses initialization of new MMT %Fact by using existend URI, _which is not checked for existence_.
/// <see cref="Normal"/> set to <c>Vector3.up</c>
/// </summary>
/// <param name="Point">sets <see cref="Point"/></param>
/// <param name="ServerDefinition">MMT URI as OMS</param>
public PyramidFact(string PidR, string PidD, SOMDoc ServerDefinition) : base()
{
this.PidR = PidR;
this.PidD = PidD;
this.ServerDefinition = ServerDefinition;
calculate_vectors();
}
/// \copydoc Fact.parseFact(ScrollFact)
public new static IEnumerator parseFact(List<Fact> ret, MMTFact fact)
{
if (((MMTGeneralFact)fact).defines is not OMA df)
yield break;
OMS rectangleR, pointD;
rectangleR = (OMS)df.arguments[0];
pointD = (OMS)df.arguments[1];
string PidR = rectangleR.uri;
string PidD = pointD.uri;
ret.Add(new PyramidFact(PidR, PidD));
//ParsingDictionary.parseTermsToId.TryAdd(defines.ToString(), fact.@ref.uri);
//ret.Add(new PointFact(SOMDoc.MakeVector3(defines), fact.@ref));
}
/// \copydoc Fact.hasDependentFacts
public override bool HasDependentFacts => true;
/// \copydoc Fact.getDependentFactIds
protected override string[] GetDependentFactIds()
=> new string[] { PidR, PidD};
/// \copydoc Fact.GetHashCode
/* public override int GetHashCode()
=> this.Point.GetHashCode();
*/
protected override void RecalculateTransform()
{
calculate_vectors();
}
/// \copydoc Fact.Equivalent(Fact, Fact)
protected override bool EquivalentWrapped(PyramidFact p1, PyramidFact p2){
}
protected override Fact _ReInitializeMe(Dictionary<string, string> old_to_new){
return new PyramidFact(this.PidR, this.PidD);
}
public override MMTFact MakeMMTDeclaration()
{
SOMDoc tp = new OMS(MMTConstants.PyramidType);
return new MMTGeneralFact(_LastLabel, tp, Defines());
}
public override SOMDoc Defines()
=> new OMA(
new OMS(MMTConstants.PyramidCons),
new[] {
new OMS(PidR),
new OMS(PidD),
}
);
}