private void AlignedCenterManager_BT1Click(object sender, EventArgs e) { if (posFlag == 2)//两点计算圆心 { float arc = arc2 - arc1; PointF p = RotateMath.RotateCenterPoint(p1, p2, arc); posFlag = 0; Common.ReportCmdKeyProgress(CmdKey.P0304); repairSucessful = true; } else if (posFlag == 3)//三点计算圆心 { float r = 0; centerPos = RotateMath.RotateCenterPoint(p1, p2, p3, out r); posFlag = 0; repairSucessful = true; Common.ReportCmdKeyProgress(CmdKey.P0309); } else { Common.ReportCmdKeyProgress(CmdKey.P0307); } cPosX.Value = centerPos.X; cPosY.Value = centerPos.Y; }
private void button2_Click(object sender, EventArgs e) { Random a = new Random(); for (int i = 0; i < 3; i++) { p[i].X = a.Next(pictureBox1.Width); p[i].Y = a.Next(pictureBox1.Height); } double angle = a.Next(360); angle = 180 - angle; using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(pictureBox1.BackColor); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; drawPen.Color = Color.Blue; drawPen.DashStyle = DashStyle.Dash; drawPen1.DashStyle = DashStyle.Dash; float r = 0; g.DrawPolygon(drawPen, p); drawPen.Color = Color.Green; g.DrawLine(drawPen, new Point(0, (int)p[0].Y), new Point(pictureBox1.Width, (int)p[0].Y)); g.DrawLine(drawPen, new Point((int)p[0].X, 0), new Point((int)p[0].X, pictureBox1.Height)); drawPen.Color = Color.DarkViolet; PointF center = RotateMath.RotateCenterPoint(p[0], p[1], p[2], out r); g.DrawPie(drawPen, new RectangleF((float)(center.X - r), (float)(center.Y - r), (float)(2 * r), (float)(2 * r)), 0, 360); g.DrawString("A", this.Font, drawBrush, p[0]); g.DrawString("B", this.Font, drawBrush, p[1]); g.DrawString("C", this.Font, drawBrush, p[2]); g.DrawString("O", this.Font, drawBrush, center); } pictureBox1.Image = bmp; }
private void Start() { var angleContainer = new Coordinate(1, 1, 1, 0); var rotationMatrixFromEulerAngles = RotateMath.GetRotationMatrixFromEulerAngles(angleContainer); _wAngle = RotateMath.ExtractAngle(rotationMatrixFromEulerAngles); _rotationAxis = RotateMath.ExtractRotationAxis(rotationMatrixFromEulerAngles); var rotateLabQuaternion = RotateMath.Quaternion(_rotationAxis, _wAngle); var unityQuaternion = Quaternion.AngleAxis(_wAngle, _rotationAxis.GetAsVector3()); Debug.Log("RotateLab quaternion is: " + rotateLabQuaternion); Debug.Log("Unity quaternion is: " + unityQuaternion.x + ", " + unityQuaternion.y + ", " + unityQuaternion.z + ", " + unityQuaternion.w); }
void Start() { var rotationMatrix = RotateMath.GetRotationMatrixFromEulerAngles(new Coordinate(_anglesContainer, 0)); Debug.Log(rotationMatrix); var extractedRotationAxis = RotateMath.ExtractRotationAxis(rotationMatrix); var extractedAngle = RotateMath.ExtractAngle(rotationMatrix); var quaternionCoord = RotateMath.Quaternion(extractedRotationAxis, extractedAngle); quaternion = new Quaternion(quaternionCoord.X, quaternionCoord.Y, quaternionCoord.Z, quaternionCoord.W); var line = new Line(new Coordinate(0, 0, 0, 1), extractedRotationAxis.GetAsVector3() * 5); line.Draw(0.1f, Color.red); }
private void button4_Click(object sender, EventArgs e) { Random a = new Random(); for (int i = 0; i < 3; i++) { p[i].X = a.Next(pictureBox1.Width); p[i].Y = a.Next(pictureBox1.Height); } using (Graphics g = Graphics.FromImage(bmp)) { g.Clear(pictureBox1.BackColor); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; drawPen.Color = Color.Blue; drawPen.DashStyle = DashStyle.Solid; g.DrawPolygon(drawPen, p); drawPen.DashStyle = DashStyle.Dash; drawPen1.DashStyle = DashStyle.Dash; drawPen.Color = Color.Green; g.DrawLine(drawPen, new Point(0, (int)p[1].Y), new Point(pictureBox1.Width, (int)p[1].Y)); g.DrawLine(drawPen, new Point((int)p[1].X, 0), new Point((int)p[1].X, pictureBox1.Height)); g.DrawString("A", this.Font, drawBrush, p[0]); g.DrawString("B", this.Font, drawBrush, p[1]); g.DrawString("C", this.Font, drawBrush, p[2]); angle = Math.Atan((p[0].Y - p[2].Y) / (p[0].X - p[2].X)); p[0] = RotateMath.PointRotate(p[1], p[0], angle); p[2] = RotateMath.PointRotate(p[1], p[2], angle); PointF p1 = new PointF((p[0].X + p[2].X) / 2, (p[0].Y + p[2].Y) / 2); g.DrawString("M'", this.Font, drawBrush, p1); g.DrawString("A'", this.Font, drawBrush, p[0]); g.DrawString("C'", this.Font, drawBrush, p[2]); angle *= -180; angle /= Math.PI; g.DrawString("当前应旋转角度为:" + angle.ToString(), this.Font, drawBrush, new PointF(10, 10)); g.DrawString("X轴移动距离为:" + (p1.X - p[1].X).ToString(), this.Font, drawBrush, new PointF(10, 30)); g.DrawString("Y轴移动距离为:" + (p1.Y - p[1].Y).ToString(), this.Font, drawBrush, new PointF(10, 50)); drawPen.Color = Color.Cyan; drawPen.DashStyle = DashStyle.Dash; g.DrawPolygon(drawPen, p); g.DrawLine(drawPen, p[1], p1); } pictureBox1.Image = bmp; }
public static PointF AlignT(PointF p1, PointF p2, PointF center, out float angle) { angle = (float)RotateMath.GetPointsAngle(p1, p2); try { if (!Globals.IsInit) { Common.ReportCmdKeyProgress(CmdKey.A0005); return(p1); } //PointF p = Com.RotateMath.PointRotate(center, new PointF((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2), a); PointF p = RotateMath.PointRotate(center, p1, angle); T_Axis.AxisJogIncWork(angle); X_Axis.JogAbs(Globals.MacData.TAdjSpeed, Globals.MacData.TAdjAcc, p.X); Y_Axis.AxisJogAbsWork(p.Y); return(p); } catch { Common.ReportCmdKeyProgress(CmdKey.S0091); return(p1); } }
private void InitCutChannelData(CutChannel c, bool create, bool res = true) { if (c.Enable) { if (c.Fixed) { if (res)//长度宽度反转 { c.Length = length; c.Width = width; } else { c.Length = width; c.Width = length; } } else { c.Length = length; c.Width = length; } c.PreWidth = PreWidth;//设置预划切宽度 c.BackSpeed = backSpeed; switch (CutMode) { case CutMode.StandOnce: case CutMode.Stand: { c.StandMode = true; c.ReDepth = ReDepth; //划切预留一 c.ReDepth2 = ReDepth2; //配置预留二 } break; case CutMode.AnyChannel: //任意通道 { c.StandMode = true; } break; case CutMode.AnyStep: { c.StandMode = false; } break; default: { c.StandMode = false; } break; } float angle = c.TRoatePos + c.TPosAdj; if (Center != Globals.TabCenter) { c.Center = RotateMath.PointRotate(Globals.TabCenter, Center, -angle); } else { c.Center = Center; } c.Fixed = this.Fixed; //圆片还是方片 c.BackSpeed = backSpeed; c.SelfPos = Globals.TestHeightValue + filmHeight + workerHeight + SelfTickness; //当前测高值+工件厚度+膜厚 + 安全预留 switch (cutDir) { case CutDir.Positive: { c.SinDir = true; c.Dir = true; } break; case CutDir.Negative: { c.SinDir = true; c.Dir = false; } break; case CutDir.TwoWay: { c.SinDir = false; c.Dir = true; } break; default: break; } c.InitCutRunData(create); } }
void Update() { var quaternion = RotateMath.Quaternion(_rotationAxis, _wAngle); transform.rotation *= new Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W); }