public static void Main(string[] args) { byte opc; TVector Vec = new TVector (); do { opc = Menu (); switch (opc) { case 1: Console.Clear (); Console.WriteLine ("Digite Tamaño: "); Vec.Tam = uint.Parse (Console.ReadLine ()); break; case 2: Vec.Llenar (); break; case 3: Mostrar (Vec.Vec); break; case 4: Mostrar ("Mayor", Vec.Mayor()); break; case 5: Mostrar ("Menor", Vec.Menor()); break; case 6: Mostrar ("Suma", Vec.Suma()); break; case 7: Mostrar ("Promedio", Vec.Promedio()); break; } } while(opc != 8); }
public void DoRotateCamera(double a) { Form1.TVector V = new TVector(); this.SetVector(ref V, this.COP.x, this.COP.y, this.COP.z); double num1 = this.VectorLength(V); double num2 = this.VRP.x - num1 * Math.Cos(this.alpha); double num3 = this.VRP.z + num1 * Math.Sin(this.alpha); this.alpha += a; while (this.alpha > 2.0 * Math.PI) { this.alpha -= 2.0 * Math.PI; } while (this.alpha < 0.0) { this.alpha += 2.0 * Math.PI; } this.VRP.x = num2 + num1 * Math.Cos(this.alpha); this.VRP.z = num3 - num1 * Math.Sin(this.alpha); this.VPN.x = -Math.Cos(this.alpha); this.VPN.z = Math.Sin(this.alpha); this.DoRedraw(); }
public async Task <IUpdates> SendUploadedDocument( IInputPeer peer, IInputFile file, string caption, string mimeType, TVector <IDocumentAttribute> attributes) { EnsureUserAuthorized(); return(await SenderService.SendRequestAsync(new RequestSendMedia { RandomId = TlHelpers.GenerateRandomLong(), Background = false, ClearDraft = false, Media = new TInputMediaUploadedDocument { File = file, Caption = caption, MimeType = mimeType, Attributes = attributes }, Peer = peer }).ConfigureAwait(false)); }
// Нахождение угла между векторами public static double GetAngleBetween2NormalVectors(TVector A, TVector B, bool Radians) { double R2D = 180 / Math.PI; // Преобразование радиан в градусы double dev, result; try { dev = Math.Sqrt(sqr(A.X) + sqr(A.Y) + sqr(A.Z)) * Math.Sqrt(sqr(B.X) + sqr(B.Y) + sqr(B.Z)); if (dev > EPS) { result = (A.X * B.X + A.Y * B.Y + A.Z * B.Z) / dev; } else { result = 0; } result = Math.Acos(result); if (!Radians) { return(result * R2D); } else { return(result); } } catch { return(0); }; }
public override void RebuildGeometry() { if (left == null) { return; } if (left != null) { mesh = left.GetTransformedMesh(); } TTriMesh right_mesh = right.GetTransformedMesh(); TTriMesh right_mesh_not_cutted = right.GetTransformedMesh(); TVector <int> v = new TVector <int>(100); for (int i = 0; i <= mesh.triangle.High; i++) { right_mesh.Cut(mesh.pos[mesh.triangle[i].p0], mesh.pos[mesh.triangle[i].p1], mesh.pos[mesh.triangle[i].p2]); } for (int i = 0; i <= right_mesh_not_cutted.triangle.High; i++) { mesh.Cut( right_mesh_not_cutted.pos[right_mesh_not_cutted.triangle[i].p0], right_mesh_not_cutted.pos[right_mesh_not_cutted.triangle[i].p1], right_mesh_not_cutted.pos[right_mesh_not_cutted.triangle[i].p2]); } for (int i = 0; i <= right_mesh.triangle.High; i++) { Vector3 tri_centre = right_mesh.pos[right_mesh.triangle[i].p0] + right_mesh.pos[right_mesh.triangle[i].p1] + right_mesh.pos[right_mesh.triangle[i].p2]; tri_centre.Multiply(1.0f / 3.0f); if (!left.Contain(tri_centre)) { v.Add(i); } } right_mesh.DelTriangles(v); v.Pop(v.Length); for (int i = 0; i <= mesh.triangle.High; i++) { Vector3 tri_centre = mesh.pos[mesh.triangle[i].p0] + mesh.pos[mesh.triangle[i].p1] + mesh.pos[mesh.triangle[i].p2]; tri_centre.Multiply(1.0f / 3.0f); if (right.Contain(tri_centre)) { v.Add(i); } } mesh.DelTriangles(v); right_mesh.InvertNormals(); mesh.Add(right_mesh); }
/// <summary>Returns chat basic info on their IDs.</summary> /// <param name="ids">Identifiers of chats</param> /// <returns>Object contains list of chats with auxiliary data.</returns> public async Task <IChats> GetChatsAsync(TVector <int> ids, CancellationToken cancellationToken = default(CancellationToken)) { AuthApiService.EnsureUserAuthorized(); var request = new RequestGetChats { Id = ids }; return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Returns chat basic info on their IDs. /// </summary> /// <param name="ids">Identifiers of chats</param> /// <returns> /// Object contains list of chats with auxiliary data. /// </returns> public async Task <IChats> GetChatsAsync(TVector <int> ids) { EnsureUserAuthorized(); var request = new RequestGetChats { Id = ids }; return(await SenderService.SendRequestAsync(request).ConfigureAwait(false)); }
/// <summary> /// Generate <see cref="TVector{T}"/> with random long numbers /// </summary> /// <param name="length">Length of list</param> /// <returns>Returns a instance of <see cref="TVector{T}"/> with random long numbers</returns> /// TODO: Move to TlHelpers? public static TVector <long> GenerateRandomTVectorLong(int length) { var randomIds = new TVector <long>(); for (int i = 0; i < length; i++) { randomIds.Items.Add(TlHelpers.GenerateRandomLong()); } return(randomIds); }
/// <summary> /// Notifies the sender about the recipient having listened a voice message or watched a video. /// </summary> /// <param name="ids">Identifiers of messages</param> /// <returns>Returns a <see cref="IAffectedMessages"/> object containing a affected messages</returns> public async Task <IAffectedMessages> ReadMessageContentsAsync(TVector <int> ids) { EnsureUserAuthorized(); var readMessageContents = new RequestReadMessageContents { Id = ids }; return(await SenderService.SendRequestAsync(readMessageContents).ConfigureAwait(false)); }
/// <summary> /// Returns the list of messages by their IDs. /// </summary> /// <param name="ids">Identifiers of messages</param> /// <returns> /// Object contains list of messages /// </returns> public async Task <IMessages> GetMessagesAsync(TVector <int> ids) { EnsureUserAuthorized(); var getMessagesRequest = new RequestGetMessages { Id = ids }; return(await SenderService.SendRequestAsync(getMessagesRequest).ConfigureAwait(false)); }
/// <summary>Notifies the sender about the recipient having listened a voice message or watched a video.</summary> /// <param name="ids">Identifiers of messages</param> /// <returns>Returns a <see cref="IAffectedMessages" /> object containing a affected messages</returns> public async Task <IAffectedMessages> ReadMessageContentsAsync(TVector <int> ids, CancellationToken cancellationToken = default(CancellationToken)) { AuthApiService.EnsureUserAuthorized(); var readMessageContents = new RequestReadMessageContents { Id = ids }; return(await SenderService.SendRequestAsync(readMessageContents, cancellationToken).ConfigureAwait(false)); }
/// <summary>Creates a new chat.</summary> /// <param name="title">Chat name</param> /// <param name="users">List of user IDs to be invited</param> /// <returns>Returns a <see cref="IUpdates" /> object containing a service message sent during an action.</returns> public async Task <IUpdates> CreateChatAsync(string title, TVector <IInputUser> users, CancellationToken cancellationToken = default(CancellationToken)) { AuthApiService.EnsureUserAuthorized(); var request = new RequestCreateChat { Title = title, Users = users }; return(await SenderService.SendRequestAsync(request, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Deletes messages by their IDs. /// </summary> /// <param name="ids">Identifiers of messages</param> /// <param name="revoke">Delete messages for everyone</param> /// <returns>Returns a <see cref="IAffectedMessages"/> object containing a affected messages</returns> public async Task <IAffectedMessages> DeleteMessagesAsync(TVector <int> ids, bool revoke) { EnsureUserAuthorized(); var deleteMessages = new RequestDeleteMessages { Id = ids, Revoke = revoke }; return(await SenderService.SendRequestAsync(deleteMessages).ConfigureAwait(false)); }
/// <summary>Deletes messages by their IDs.</summary> /// <param name="ids">Identifiers of messages</param> /// <param name="revoke">Delete messages for everyone</param> /// <returns>Returns a <see cref="IAffectedMessages" /> object containing a affected messages</returns> public async Task <IAffectedMessages> DeleteMessagesAsync(TVector <int> ids, bool revoke, CancellationToken cancellationToken = default(CancellationToken)) { AuthApiService.EnsureUserAuthorized(); var deleteMessages = new RequestDeleteMessages { Id = ids, Revoke = revoke }; return(await SenderService.SendRequestAsync(deleteMessages, cancellationToken).ConfigureAwait(false)); }
/// <summary> /// Creates a new chat. /// </summary> /// <param name="title">Chat name</param> /// <param name="users">List of user IDs to be invited</param> /// <returns> /// Returns a <see cref="IUpdates"/> object containing a service message sent during an action. /// </returns> public async Task <IUpdates> CreateChatAsync(string title, TVector <IInputUser> users) { EnsureUserAuthorized(); var request = new RequestCreateChat { Title = title, Users = users }; return(await SenderService.SendRequestAsync(request).ConfigureAwait(false)); }
//{ Нахождение нормали к поверхности, заданной двумя векторами} public static TVector GetNormalVectorFrom2DecVectors(TVector A, TVector B) { TVector C = new TVector(); try { C.X = A.Y * B.Z - B.Y * A.Z; C.Y = A.Z * B.X - B.Z * A.X; C.Z = A.X * B.Y - B.X * A.Y; return(C); } catch { return(C); }; }
// Конструктор по углу и вектору вращения public TQuaternion(double phi, TVector V) { if (V.Vector.Length != 3) { return; } Vec = new double[4]; Vec[0] = Math.Cos(phi * (Math.PI) / 360); for (int i = 1; i < 4; i++) { Vec[i] = Math.Sin(phi * (Math.PI) / 360) * V.Vector[i - 1]; } }
void SubDiv(TVector <Vector3> vertex, TVector <TRib> rib, TVector <TTri> tri) { int high = rib.High;//т.к. будем добавлять в этот массив for (int i = 0; i <= high; i++) { if (!rib[i].cutted) { Vector3 new_vert = vertex[rib[i].v0] + vertex[rib[i].v1]; new_vert.Multiply(0.5f); vertex.Add(new_vert); TRib new_rib = rib[i]; new_rib.middle = vertex.High; new_rib.cutted = true; rib.Add(new TRib(vertex.High, new_rib.v0)); rib.Add(new TRib(vertex.High, new_rib.v1)); new_rib.part0 = rib.High - 1; new_rib.part1 = rib.High; rib[i] = new_rib; } } //TODO кучу неиспользуемых посеченных ребер хранить не обязательно high = tri.High; for (int i = 0; i <= high; i++) { TTri last_tri = tri[i]; { int v0 = rib[tri[i].r0].middle; int v1 = rib[tri[i].r1].middle; int v2 = rib[tri[i].r2].middle; rib.Add(new TRib(v0, v1)); rib.Add(new TRib(v1, v2)); rib.Add(new TRib(v2, v0)); tri.Add(new TTri(rib.High - 2, rib.High - 1, rib.High)); } // int p0 = rib[last_tri.r0].GetCommonPart(rib, rib[last_tri.r1]); int p1 = rib[last_tri.r1].GetCommonPart(rib, rib[last_tri.r0]); tri[i] = new TTri(p0, p1, rib.High - 2); // p0 = rib[last_tri.r0].GetCommonPart(rib, rib[last_tri.r2]); p1 = rib[last_tri.r2].GetCommonPart(rib, rib[last_tri.r0]); tri.Add(new TTri(p0, rib.High, p1)); // p0 = rib[last_tri.r1].GetCommonPart(rib, rib[last_tri.r2]); p1 = rib[last_tri.r2].GetCommonPart(rib, rib[last_tri.r1]); tri.Add(new TTri(p0, p1, rib.High - 1)); } }
public async Task ForwardMessage(TUpdateShortMessage message) { var messages = new TVector <int>(); messages.Items.Add(message.Id); await telegramClient.MessagesService.ForwardMessagesAsync(new TInputPeerUser() { UserId = message.UserId }, new TInputPeerUser() { UserId = _user.Id }, messages, true, true); }
public int GetCommonPart(TVector <TRib> rib, TRib neighbour_rib) { //возвращает индекс part данного rib соседствующего с neighbour_rib int p = GetCommonVert(neighbour_rib); if (rib[part0].HasVert(p)) { return(part0); } else { Debug.Assert(rib[part1].HasVert(p)); return(part1); } }
public async Task CheckUpdates(IUpdates x) { if (x is TUpdateShortMessage) { var TMessage = x as TUpdateShortMessage; //await client.MessagesService.ForwardMessageAsync(new TInputPeerUser() { UserId = _user.Id, AccessHash = _user.AccessHash}, TMessage.Id); var messages = new TVector <int>(); messages.Items.Add(TMessage.Id); await client.MessagesService.ForwardMessagesAsync(new TInputPeerUser() { UserId = TMessage.UserId }, new TInputPeerUser() { UserId = _user.Id }, messages, true, true); } }
//{ Перевод из географической в декартовую систему координат } public static TVector GeographicToDecVector(double Lat, double Long, double radius, bool radians) { double D2R = Math.PI / 180; double conv = 1; TVector result = new TVector(); if (!radians) { conv = D2R; } try { result.X = radius * Math.Cos(Long * conv) * Math.Sin(Lat * conv); result.Y = radius * Math.Sin(Long * conv) * Math.Sin(Lat * conv); result.Z = radius * Math.Cos(Lat * conv); return(result); } catch { return(result); } }
private void Eiler_Click(object sender, EventArgs e)//ЭЙЛЕР { if (PointsEiler == null) { PointsEiler = ReadFile("result_TEuler.txt"); } Graphics g = GraphXYZ.CreateGraphics(); Graphics gr = GraphSpeed.CreateGraphics(); Pen myPen1 = new Pen(Color.Blue); Pen myPen2 = new Pen(Color.Red); Pen myPen3 = new Pen(Color.Green); Pen myPen4 = new Pen(Color.Black, 2); double xmax = PointsEiler.Count; double ymax = Math.Max(Math.Max(PointsEiler.Max(x => Math.Abs(x.Vec[0])), PointsEiler.Max(x => Math.Abs(x.Vec[1]))), PointsEiler.Max(x => Math.Abs(x.Vec[2]))); //масштаб double kx = GraphXYZ.Width / xmax; double ky = GraphXYZ.Height / ymax / 2.8; TVector PrevPoint = PointsEiler.FirstOrDefault(); PrevPoint.Vec = new double[6] { 0, 0, 0, 0, 0, 0 }; //ОСИ g.DrawLine(myPen4, 0, GraphXYZ.Height / 2, GraphXYZ.Width, GraphXYZ.Height / 2); g.DrawLine(myPen4, 10, 10, 10, GraphXYZ.Height - 10); //КООРДИНАТЫ int index = 0; Font drawFont = new Font("Arial", 12); SolidBrush drawBrush1 = new SolidBrush(Color.Blue); g.DrawString("X", drawFont, drawBrush1, new Point(10, 10)); SolidBrush drawBrush2 = new SolidBrush(Color.Red); g.DrawString("Y", drawFont, drawBrush2, new Point(10, 30)); SolidBrush drawBrush3 = new SolidBrush(Color.Green); g.DrawString("Z", drawFont, drawBrush3, new Point(10, 50)); foreach (var Point in PointsEiler) { g.DrawLine(myPen1, (int)(kx * index), (int)(GraphXYZ.Height / 2 + ky * PrevPoint.Vec[0]), (int)(kx * (index + 1)), (int)(GraphXYZ.Height / 2 + ky * Point.Vec[0])); g.DrawLine(myPen2, (int)(kx * index), (int)(GraphXYZ.Height / 2 + ky * PrevPoint.Vec[1]), (int)(kx * (index + 1)), (int)(GraphXYZ.Height / 2 + ky * Point.Vec[1])); g.DrawLine(myPen3, (int)(kx * index), (int)(GraphXYZ.Height / 2 + ky * PrevPoint.Vec[2]), (int)(kx * (index + 1)), (int)(GraphXYZ.Height / 2 + ky * Point.Vec[2])); PrevPoint = Point; index++; } //СКОРОСТИ ymax = Math.Max(Math.Max(PointsEiler.Max(x => Math.Abs(x.Vec[3])), PointsEiler.Max(x => Math.Abs(x.Vec[4]))), PointsEiler.Max(x => Math.Abs(x.Vec[5]))); ky = GraphXYZ.Height / ymax / 2.8; gr.DrawLine(myPen4, 0, GraphXYZ.Height / 2, GraphXYZ.Width, GraphXYZ.Height / 2); gr.DrawLine(myPen4, 10, 10, 10, GraphXYZ.Height - 10); index = 0; gr.DrawString("Ux", drawFont, drawBrush1, new Point(10, 10)); gr.DrawString("Uy", drawFont, drawBrush2, new Point(10, 30)); gr.DrawString("Uz", drawFont, drawBrush3, new Point(10, 50)); foreach (var Point in PointsEiler) { gr.DrawLine(myPen1, (int)(kx * index), (int)(GraphXYZ.Height / 2 + ky * PrevPoint.Vec[3]), (int)(kx * (index + 1)), (int)(GraphXYZ.Height / 2 + ky * Point.Vec[3])); gr.DrawLine(myPen2, (int)(kx * index), (int)(GraphXYZ.Height / 2 + ky * PrevPoint.Vec[4]), (int)(kx * (index + 1)), (int)(GraphXYZ.Height / 2 + ky * Point.Vec[4])); gr.DrawLine(myPen3, (int)(kx * index), (int)(GraphXYZ.Height / 2 + ky * PrevPoint.Vec[5]), (int)(kx * (index + 1)), (int)(GraphXYZ.Height / 2 + ky * Point.Vec[5])); PrevPoint = Point; index++; } }
void RebuildMesh() { TVector <Vector3> vertex = new TVector <Vector3>(6 * (int)Math.Pow(2, sub_div)); TVector <TRib> rib = new TVector <TRib>(100);//TODO размер динамически от sub_div TVector <TTri> tri = new TVector <TTri>(100); // vertex.Add(new Vector3(0, 0, radius)); vertex.Add(new Vector3(-radius, 0, 0)); vertex.Add(new Vector3(0, 0, -radius)); vertex.Add(new Vector3(radius, 0, 0)); vertex.Add(new Vector3(0, radius, 0)); vertex.Add(new Vector3(0, -radius, 0)); // rib.Add(new TRib(0, 4)); rib.Add(new TRib(1, 4)); rib.Add(new TRib(2, 4)); rib.Add(new TRib(3, 4)); rib.Add(new TRib(0, 1)); rib.Add(new TRib(1, 2)); rib.Add(new TRib(2, 3)); rib.Add(new TRib(3, 0)); rib.Add(new TRib(0, 5)); rib.Add(new TRib(1, 5)); rib.Add(new TRib(2, 5)); rib.Add(new TRib(3, 5)); // tri.Add(new TTri(0, 1, 4)); tri.Add(new TTri(1, 2, 5)); tri.Add(new TTri(2, 3, 6)); tri.Add(new TTri(3, 0, 7)); tri.Add(new TTri(8, 4, 9)); tri.Add(new TTri(9, 5, 10)); tri.Add(new TTri(10, 6, 11)); tri.Add(new TTri(11, 7, 8)); // for (int i = 0; i < sub_div; i++) { SubDiv(vertex, rib, tri); } mesh.pos.Pop(mesh.pos.Length); mesh.normal.Pop(mesh.normal.Length); mesh.triangle.Pop(mesh.triangle.Length); for (int i = 0; i <= vertex.High; i++) { Vector3 v = vertex[i]; v.Normalize(); v.Multiply(radius); vertex[i] = v; } mesh.pos.Add(vertex); mesh.normal.Add(vertex); for (int i = 0; i <= vertex.High; i++) { Vector3 norm = vertex[i]; norm.Normalize(); mesh.normal[i] = norm; } //float max_rib_length_sq = 0; min_rad = radius; //for (int i = 0; i <= rib.High; i++) //{ // if (rib[i].cutted) continue; // Vector3 p0 = vertex[rib[i].v0]; // Vector3 p1 = vertex[rib[i].v1]; // Vector3 p2 = vertex[rib[i].v2]; // Vector3 n = Vector3.Cross(p1 - p0, p2 - p0); // n.Normalize(); // float temp = Vector3.Dot(n,p0); // //if (temp > max_rib_length_sq) max_rib_length_sq = temp; // //if (temp < min_rib_length_sq) min_rib_length_sq = temp; //} //min_rad = (float)Math.Sqrt(radius * radius - max_rib_length_sq /4); for (int i = 0; i <= tri.High; i++) { int v0 = rib[tri[i].r0].GetCommonVert(rib[tri[i].r1]); int v1 = rib[tri[i].r1].GetOtherVert(v0); int v2 = rib[tri[i].r2].GetOtherVert(v1); mesh.triangle.Add(new TTriMesh.TMeshTri(v0, v1, v2, v0, v1, v2, 0, 0, 0)); } for (int i = 0; i <= tri.High; i++) { if (rib[i].cutted) { continue; } Vector3 p0 = mesh.pos[mesh.triangle[i].p0]; Vector3 p1 = mesh.pos[mesh.triangle[i].p1]; Vector3 p2 = mesh.pos[mesh.triangle[i].p2]; Vector3 n = Vector3.Cross(p1 - p0, p2 - p0); n.Normalize(); float temp = Vector3.Dot(n, p0); if (temp < min_rad) { min_rad = temp; } //if (temp > max_rib_length_sq) max_rib_length_sq = temp; //if (temp < min_rib_length_sq) min_rib_length_sq = temp; } need_update = true; }
/// <summary> /// Forwards messages by their IDs. /// </summary> /// <param name="fromPeer">User or chat from where a message will be forwarded</param> /// <param name="toPeer">User or chat where a message will be forwarded</param> /// <param name="ids">Forwarded message IDs</param> /// <param name="silent"></param> /// <param name="withMyScore"></param> /// <returns>Returns a <see cref="IUpdates"/> object containing a service message sent during an action.</returns> public async Task <IUpdates> ForwardMessagesAsync(IInputPeer fromPeer, IInputPeer toPeer, TVector <int> ids, bool silent, bool withMyScore) { EnsureUserAuthorized(); var forwardMessages = new RequestForwardMessages { FromPeer = fromPeer, ToPeer = toPeer, Id = ids, Background = false, Silent = silent, WithMyScore = withMyScore, RandomId = TlHelpers.GenerateRandomTVectorLong(ids.Items.Count) }; return(await SenderService.SendRequestAsync(forwardMessages)); }
public void RebuildMesh() { if (operand.Count == 0) { return; } mesh = operand[0].GetTransformedMesh(); for (int c = 1; c < operand.Count; c++) { TTriMesh right_mesh = operand[c].GetTransformedMesh(); TTriMesh right_mesh_not_cutted = operand[c].GetTransformedMesh(); TVector <int> v = new TVector <int>(100); for (int i = 0; i <= mesh.triangle.High; i++) { right_mesh.Cut(mesh.pos[mesh.triangle[i].p0], mesh.pos[mesh.triangle[i].p1], mesh.pos[mesh.triangle[i].p2]); } for (int i = 0; i <= right_mesh_not_cutted.triangle.High; i++) { mesh.Cut( right_mesh_not_cutted.pos[right_mesh_not_cutted.triangle[i].p0], right_mesh_not_cutted.pos[right_mesh_not_cutted.triangle[i].p1], right_mesh_not_cutted.pos[right_mesh_not_cutted.triangle[i].p2]); } for (int i = 0; i <= right_mesh.triangle.High; i++) { Vector3 tri_centre = right_mesh.pos[right_mesh.triangle[i].p0] + right_mesh.pos[right_mesh.triangle[i].p1] + right_mesh.pos[right_mesh.triangle[i].p2]; tri_centre.Multiply(1.0f / 3.0f); switch (op_type) { case TBoolOpType.NOT: if (!operand[0].Contain(tri_centre)) { v.Add(i); } else { for (int k = 1; k < c; k++) { if (operand[k].Contain(tri_centre)) { v.Add(i); break; } } } break; case TBoolOpType.OR: for (int k = 0; k < c; k++) { if (operand[k].Contain(tri_centre)) { v.Add(i); break; } } break; case TBoolOpType.AND: for (int k = 0; k < c; k++) { if (!operand[k].Contain(tri_centre)) { v.Add(i); break; } } break; } } right_mesh.DelTriangles(v); v.Pop(v.Length); for (int i = 0; i <= mesh.triangle.High; i++) { Vector3 tri_centre = mesh.pos[mesh.triangle[i].p0] + mesh.pos[mesh.triangle[i].p1] + mesh.pos[mesh.triangle[i].p2]; tri_centre.Multiply(1.0f / 3.0f); switch (op_type) { case TBoolOpType.NOT: if (operand[c].Contain(tri_centre)) { v.Add(i); } break; case TBoolOpType.OR: if (operand[c].Contain(tri_centre)) { v.Add(i); } break; case TBoolOpType.AND: if (!operand[c].Contain(tri_centre)) { v.Add(i); } break; } } mesh.DelTriangles(v); if (op_type == TBoolOpType.NOT) { right_mesh.InvertNormals(); } mesh.Add(right_mesh); } }
public void DoRedraw() { this.ClearWindow(); this.n = this.UnitVector(this.VPN); this.v = this.UnitVector(this.AddVectors(this.VUP, this.MultiplyVector(-1.0 * this.DotProduct(this.n, this.VUP), this.n))); this.u = this.UnitVector(this.CrossProduct(this.v, this.n)); // ini declare matrix M dari PPT 5 slide 9 double[,] M = new double[4, 4]; this.SetRowMatrix(ref M, 0, this.u.x, this.v.x, this.n.x, 0.0); this.SetRowMatrix(ref M, 1, this.u.y, this.v.y, this.n.y, 0.0); this.SetRowMatrix(ref M, 2, this.u.z, this.v.z, this.n.z, 0.0); this.SetRowMatrix(ref M, 3, 0.0, 0.0, 0.0, 1.0); this.VRPV = this.Generate3Dto2D(this.VRP, M); this.SetPoint(ref this.WC, (this.wxmin + this.wxmax) / 2.0, (this.wymin + this.wymax) / 2.0, 0.0); this.SetVector(ref this.DOP, this.WC.x - this.COP.x, this.WC.y - this.COP.y, this.WC.z - this.COP.z); this.v3 = -this.COP.z; // VP3 this.shx = -this.DOP.x / this.DOP.z; //-DOPx based dari ppt this.shy = -this.DOP.y / this.DOP.z; // -//- -DOPy based dari ppt this.BP4 = this.BP - this.COP.z; // B4/B3 (Back plane yang udah melakukan 4 transformasi this.sx = 2.0 * -this.COP.z / ((this.wxmax - this.wxmin) * this.BP4); this.sy = 2.0 * -this.COP.z / ((this.wymax - this.wymin) * this.BP4); this.sz = -1.0 / (this.BP - this.COP.z); this.zmin = -((-this.COP.z + this.FP) / this.BP4); // v5 this.v5 = this.v3 * this.sz; this.vmax7 = this.COP.z / (this.COP.z - this.BP); this.num8 = this.COP.z / (this.COP.z - this.BP); this.zmax = -1.0; this.SetRowMatrix(ref this.T1T2, 0, this.u.x, this.v.x, this.n.x, 0.0); this.SetRowMatrix(ref this.T1T2, 1, this.u.y, this.v.y, this.n.y, 0.0); this.SetRowMatrix(ref this.T1T2, 2, this.u.z, this.v.z, this.n.z, 0.0); this.SetRowMatrix(ref this.T1T2, 3, -this.VRPV.x, -this.VRPV.y, -this.VRPV.z, 1.0); // PPT 5 slide 12, this.SetRowMatrix(ref this.T3, 0, 1.0, 0.0, 0.0, 0.0); this.SetRowMatrix(ref this.T3, 1, 0.0, 1.0, 0.0, 0.0); this.SetRowMatrix(ref this.T3, 2, 0.0, 0.0, 1.0, 0.0); this.SetRowMatrix(ref this.T3, 3, -this.COP.x, -this.COP.y, -this.COP.z, 1.0); // -COPx sama kayak -eu di ppt 5 slide 27. bedanya COPx itu coordinate COP yang ada di WCS this.SetRowMatrix(ref this.T4, 0, 1.0, 0.0, 0.0, 0.0); this.SetRowMatrix(ref this.T4, 1, 0.0, 1.0, 0.0, 0.0); this.SetRowMatrix(ref this.T4, 2, this.shx, this.shy, 1.0, 0.0); this.SetRowMatrix(ref this.T4, 3, 0.0, 0.0, 0.0, 1.0); this.SetRowMatrix(ref this.T5, 0, this.sx, 0.0, 0.0, 0.0); this.SetRowMatrix(ref this.T5, 1, 0.0, this.sy, 0.0, 0.0); this.SetRowMatrix(ref this.T5, 2, 0.0, 0.0, this.sz, 0.0); this.SetRowMatrix(ref this.T5, 3, 0.0, 0.0, 0.0, 1.0); this.SetRowMatrix(ref this.T6, 0, 1.0, 0.0, 0.0, 0.0); this.SetRowMatrix(ref this.T6, 1, 0.0, 1.0, 0.0, 0.0); this.SetRowMatrix(ref this.T6, 2, 0.0, 0.0, 1.0 / (1.0 + this.zmin), this.zmax); this.SetRowMatrix(ref this.T6, 3, 0.0, 0.0, -this.zmin / (1.0 + this.zmin), 0.0); this.SetRowMatrix(ref this.T7, 0, 1.0, 0.0, 0.0, 0.0); this.SetRowMatrix(ref this.T7, 1, 0.0, 1.0, 0.0, 0.0); this.SetRowMatrix(ref this.T7, 2, 0.0, 0.0, 1.0, vmax7); this.SetRowMatrix(ref this.T7, 3, 0.0, 0.0, 0.0, 1.0); this.SetRowMatrix(ref this.T8, 0, 1.0 / num8, 0.0, 0.0, 0.0); this.SetRowMatrix(ref this.T8, 1, 0.0, 1.0 / num8, 0.0, 0.0); this.SetRowMatrix(ref this.T8, 2, 0.0, 0.0, 1.0, 0.0); this.SetRowMatrix(ref this.T8, 3, 0.0, 0.0, -1.0 / num8, 1.0); this.SetCubes(); this.TransformCubes(this.T1T2); this.TransformCubes(this.T3); this.TransformCubes(this.T4); this.TransformCubes(this.T5); this.TransformCubes(this.T6); this.TransformCubeS(this.T7); this.TransformCubeS(this.T8); this.DrawCubes(); this.DrawWindow(); this.boxCanvas.Image = (Image)this.window; }
private static HessMatrix GetHessCoarseResiIterImpl_Matlab_IterLowerTri_Get_BInvDC (HessMatrix A , HessMatrix C , HessMatrix D , bool process_disp_console , string[] options , double?thld_BinvDC = null , bool parallel = false ) { if (options == null) { options = new string[0]; } HessMatrix B_invD_C; Dictionary <int, int> Cbr_CCbr = new Dictionary <int, int>(); List <int> CCbr_Cbr = new List <int>(); foreach (ValueTuple <int, int, MatrixByArr> bc_br_bval in C.EnumBlocks()) { int Cbr = bc_br_bval.Item2; if (Cbr_CCbr.ContainsKey(Cbr) == false) { HDebug.Assert(Cbr_CCbr.Count == CCbr_Cbr.Count); int CCbr = Cbr_CCbr.Count; Cbr_CCbr.Add(Cbr, CCbr); CCbr_Cbr.Add(Cbr); HDebug.Assert(CCbr_Cbr[CCbr] == Cbr); } } HessMatrix CC = C.Zeros(C.ColSize, Cbr_CCbr.Count * 3); { Action <ValueTuple <int, int, MatrixByArr> > func = delegate(ValueTuple <int, int, MatrixByArr> bc_br_bval) { int Cbc = bc_br_bval.Item1; int CCbc = Cbc; int Cbr = bc_br_bval.Item2; int CCbr = Cbr_CCbr[Cbr]; var bval = bc_br_bval.Item3; lock (CC) CC.SetBlock(CCbc, CCbr, bval); }; if (parallel) { Parallel.ForEach(C.EnumBlocks(), func); } else { foreach (var bc_br_bval in C.EnumBlocks()) { func(bc_br_bval); } } } if (process_disp_console) { System.Console.Write("squeezeC({0,6}->{1,6} blk), ", C.RowBlockSize, CC.RowBlockSize); } { /// If a diagonal element of D is null, that row and column should be empty. /// This assume that the atom is removed. In this case, the removed diagonal block /// is replace as the 3x3 identity matrix. /// /// [B1 0] [ A 0 ]^-1 [C1 C2 C3] = [B1 0] [ A^-1 0 ] [C1 C2 C3] /// [B2 0] [ 0 I ] [ 0 0 0] [B2 0] [ 0 I^-1 ] [ 0 0 0] /// [B3 0] [B3 0] /// = [B1.invA 0] [C1 C2 C3] /// [B2.invA 0] [ 0 0 0] /// [B3.invA 0] /// = [B1.invA.C1 B1.invA.C2 B1.invA.C3] /// [B2.invA.C1 B2.invA.C2 B2.invA.C3] /// [B3.invA.C1 B3.invA.C2 B3.invA.C3] /// { //HDebug.Exception(D.ColBlockSize == D.RowBlockSize); for (int bi = 0; bi < D.ColBlockSize; bi++) { if (D.HasBlock(bi, bi) == true) { continue; } //for(int bc=0; bc< D.ColBlockSize; bc++) HDebug.Exception( D.HasBlock(bc, bi) == false); //for(int br=0; br< D.RowBlockSize; br++) HDebug.Exception( D.HasBlock(bi, br) == false); //for(int br=0; br<CC.RowBlockSize; br++) HDebug.Exception(CC.HasBlock(bi, br) == false); D.SetBlock(bi, bi, new double[3, 3] { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }); } } HessMatrix BB_invDD_CC; using (new Matlab.NamedLock("")) { Matlab.Execute("clear;"); if (process_disp_console) { System.Console.Write("matlab("); } Matlab.PutMatrix("C", CC); if (process_disp_console) { System.Console.Write("C"); //Matlab.PutSparseMatrix("C", CC.GetMatrixSparse(), 3, 3); } Matlab.PutMatrix("D", D); if (process_disp_console) { System.Console.Write("D"); } // Matlab.Execute("BinvDC = (C' / D) * C;"); { if (options.Contains("pinv(D)")) { Matlab.Execute("BinvDC = C' * pinv(D) * C;"); } if (options.Contains("/D -> pinv(D)")) { string msg = Matlab.Execute("BinvDC = (C' / D) * C;", true); if (msg != "") { Matlab.Execute("BinvDC = C' * pinv(D) * C;"); } } else if (options.Contains("/D")) { Matlab.Execute("BinvDC = (C' / D) * C;"); } else { Matlab.Execute("BinvDC = (C' / D) * C;"); } } if (process_disp_console) { System.Console.Write("X"); } //Matrix BBinvDDCC = Matlab.GetMatrix("BinvDC", true); if (thld_BinvDC != null) { Matlab.Execute("BinvDC(find(BinvDC < " + thld_BinvDC.ToString() + ")) = 0;"); } if (Matlab.GetValue("nnz(BinvDC)/numel(BinvDC)") > 0.5 || HDebug.True) { Func <int, int, HessMatrix> Zeros = delegate(int colsize, int rowsize) { return(HessMatrixDense.ZerosDense(colsize, rowsize)); }; BB_invDD_CC = Matlab.GetMatrix("BinvDC", Zeros, true); if (process_disp_console) { System.Console.Write("Y), "); } } else { Matlab.Execute("[i,j,s] = find(sparse(BinvDC));"); TVector <int> listi = Matlab.GetVectorLargeInt("i", true); TVector <int> listj = Matlab.GetVectorLargeInt("j", true); TVector <double> lists = Matlab.GetVectorLarge("s", true); int colsize = Matlab.GetValueInt("size(BinvDC,1)"); int rowsize = Matlab.GetValueInt("size(BinvDC,2)"); Dictionary <ValueTuple <int, int>, MatrixByArr> lst_bc_br_bval = new Dictionary <ValueTuple <int, int>, MatrixByArr>(); for (long i = 0; i < listi.SizeLong; i++) { int c = listi[i] - 1; int bc = c / 3; int ic = c % 3; int r = listj[i] - 1; int br = r / 3; int ir = r % 3; double v = lists[i]; ValueTuple <int, int> bc_br = new ValueTuple <int, int>(bc, br); if (lst_bc_br_bval.ContainsKey(bc_br) == false) { lst_bc_br_bval.Add(bc_br, new double[3, 3]); } lst_bc_br_bval[bc_br][ic, ir] = v; } // Matrix BBinvDDCC = Matrix.Zeros(colsize, rowsize); // for(int i=0; i<listi.Length; i++) // BBinvDDCC[listi[i]-1, listj[i]-1] = lists[i]; // //GC.Collect(0); BB_invDD_CC = D.Zeros(colsize, rowsize); foreach (var bc_br_bval in lst_bc_br_bval) { int bc = bc_br_bval.Key.Item1; int br = bc_br_bval.Key.Item2; var bval = bc_br_bval.Value; BB_invDD_CC.SetBlock(bc, br, bval); } if (process_disp_console) { System.Console.Write("Z), "); } if (HDebug.IsDebuggerAttached) { for (int i = 0; i < listi.Size; i++) { int c = listi[i] - 1; int r = listj[i] - 1; double v = lists[i]; HDebug.Assert(BB_invDD_CC[c, r] == v); } } } Matlab.Execute("clear;"); } //GC.Collect(0); B_invD_C = A.Zeros(C.RowSize, C.RowSize); { // for(int bcc=0; bcc<CCbr_Cbr.Count; bcc++) // { // int bc = CCbr_Cbr[bcc]; // for(int brr=0; brr<CCbr_Cbr.Count; brr++) // { // int br = CCbr_Cbr[brr]; // HDebug.Assert(B_invD_C.HasBlock(bc, br) == false); // if(BB_invDD_CC.HasBlock(bcc, brr) == false) // continue; // var bval = BB_invDD_CC.GetBlock(bcc, brr); // B_invD_C.SetBlock(bc, br, bval); // HDebug.Exception(A.HasBlock(bc, bc)); // HDebug.Exception(A.HasBlock(br, br)); // } // } Action <ValueTuple <int, int, MatrixByArr> > func = delegate(ValueTuple <int, int, MatrixByArr> bcc_brr_bval) { int bcc = bcc_brr_bval.Item1; int brr = bcc_brr_bval.Item2; var bval = bcc_brr_bval.Item3; int bc = CCbr_Cbr[bcc]; int br = CCbr_Cbr[brr]; //lock(B_invD_C) B_invD_C.SetBlockLock(bc, br, bval); }; if (parallel) { Parallel.ForEach(BB_invDD_CC.EnumBlocks(), func); } else { foreach (var bcc_brr_bval in BB_invDD_CC.EnumBlocks()) { func(bcc_brr_bval); } } } } GC.Collect(0); return(B_invD_C); }