public static Vector2 Get(Axis2 axis, Device device) { CheckInstance(); var data = _instance._GetAxis(_instance.axis2Handles[(int)axis], device); return(new Vector2(data.x, data.y)); }
private void CommandInit_Click(object sender, EventArgs e) { CommandStart.Enabled = true; //радиусы колес R1 = float.Parse(TextR1.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo); //неподвижное R = float.Parse(TexTR.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo); //колесо подвижное if (R > R1) { MessageBox.Show("Радиус внутреннего колеса должен быть меньше радиуса наружного!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { Fimax = float.Parse(TextFiMax.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo); DeltaFi = float.Parse(TextDeltaFi.Text, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.NumberFormatInfo.InvariantInfo); //размеры полей отображения XBase = (float)Round(R1 + 1.2); YBase = (float)Round(R1 + 1.2); InitAxis(); //Колесо неподвижное Xo1 = 0; Yo1 = 0; Axis1.Pix_type = 3; Axis1.Pix_Size = 2 * R1 / XBase; Axis1.PixDraw(Xo1, Yo1, Color.Black, 1); //Колесо подвижное Xo = R1 - R; Yo = 0; Axis1.Pix_Size = 2 * R / XBase; Axis1.PixDraw(Xo, Yo, Color.Blue, 2); //Начальные координаты точки А Xa = R1; Ya = 0; //радиус Axis1.Pix_color = Color.Black; Axis1.Line(Xa, Ya, Xo, Yo, 2); Axis1.DinToPic(); m = R / R1; Fi = 0; //Отображение траектории точки А while (Fi < Fimax) { X = (float)((R1 - R) * Cos(m * Fi) + R * Cos(Fi - m * Fi)); Y = (float)((R1 - R) * Sin(m * Fi) - R * Sin(Fi - m * Fi)); Axis2.PixDraw(X, Y, Color.Black, 0); Fi = Fi + DeltaFi; } ; Fi = 0; } }
public static float Component(this Vector2 v, Axis2 axis) { switch (axis) { case Axis2.Horizontal: return(v.x); case Axis2.Vertical: return(v.y); default: throw new UnexpectedEnumValueException <Axis2>(axis); } }
public static Vector2 UnaryVector(this Axis2 axis) { switch (axis) { case Axis2.Horizontal: return(Vector2.right); case Axis2.Vertical: return(Vector2.up); default: throw new UnexpectedEnumValueException <Axis2>(axis); } }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(Axis1 != null ? Axis1.ToStepValue() : "$"); parameters.Add(Axis2 != null ? Axis2.ToStepValue() : "$"); parameters.Add(LocalOrigin != null ? LocalOrigin.ToStepValue() : "$"); parameters.Add(Scale != null ? Scale.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
public static Axis2 Perpendicular(this Axis2 axis) { switch (axis) { case Axis2.Horizontal: return(Axis2.Vertical); case Axis2.Vertical: return(Axis2.Horizontal); default: throw new UnexpectedEnumValueException <Axis2>(axis); } }
public static bool Contains(this Axes2 axes, Axis2 axis) { // Avoid HasFlag for speed and memory switch (axis) { case Axis2.Horizontal: return((axes & Axes2.Horizontal) != 0); case Axis2.Vertical: return((axes & Axes2.Vertical) != 0); default: throw new UnexpectedEnumValueException <Axis2>(axis); } }
public static Vector2 WithComponent(this Vector2 v, float c, Axis2 axis) { switch (axis) { case Axis2.Horizontal: v.x = c; break; case Axis2.Vertical: v.y = c; break; default: throw new UnexpectedEnumValueException <Axis2>(axis); } return(v); }
public void Draw() { foreach (var data in this.Data) { data.Draw(this.Sprites, this.Axis1, this.Axis2, this.Offset); } Axis1.Draw(this.Sprites, Vector2.UnitX, this.Offset); Axis2.Draw(this.Sprites, Vector2.UnitY, this.Offset); if (this.Grid != null) { this.Grid.Draw(this.Sprites, this.Axis1, this.Axis2, this.Offset); } }
public void MoveEllipse(double deltaX, double deltaY) { Center.Move(deltaX, deltaY); Vertex1.Move(deltaX, deltaY); Vertex2.Move(deltaX, deltaY); Vertex3.Move(deltaX, deltaY); Vertex4.Move(deltaX, deltaY); Foci1.Move(deltaX, deltaY); Foci2.Move(deltaX, deltaY); Axis1.Move(deltaX, deltaY); Axis2.Move(deltaX, deltaY); BindingRectangle.Move(deltaX, deltaY); }
public void InitAxis() { Axis1.Axis_Type = 1; Axis1.x_Base = XBase; Axis1.y_Base = YBase; Axis1.AxisDraw(); Axis2.Axis_Type = 1; Axis2.Pix_type = 1; Axis2.x_Base = XBase; Axis2.y_Base = YBase; Axis2.Pix_Size = 0; Axis2.AxisDraw(); }
protected override void setJSON(JObject obj, BaseClassIfc host, HashSet <int> processed) { base.setJSON(obj, host, processed); if (mAxis1 > 0) { obj["Axis1"] = Axis1.getJson(this, processed); } if (mAxis2 > 0) { obj["Axis2"] = Axis2.getJson(this, processed); } obj["LocalOrigin"] = LocalOrigin.getJson(this, processed); if (!double.IsNaN(mScale)) { obj["Scale"] = Scale; } }
internal override void SetXML(XmlElement xml, BaseClassIfc host, Dictionary <int, XmlElement> processed) { base.SetXML(xml, host, processed); if (mAxis1 > 0) { xml.AppendChild(Axis1.GetXML(xml.OwnerDocument, "Axis1", this, processed)); } if (mAxis2 > 0) { xml.AppendChild(Axis2.GetXML(xml.OwnerDocument, "Axis2", this, processed)); } xml.AppendChild(LocalOrigin.GetXML(xml.OwnerDocument, "LocalOrigin", this, processed)); if (!double.IsNaN(mScale)) { xml.SetAttribute("Scale", mScale.ToString()); } }
protected override void setJSON(JObject obj, BaseClassIfc host, SetJsonOptions options) { base.setJSON(obj, host, options); if (mAxis1 > 0) { obj["Axis1"] = Axis1.getJson(this, options); } if (mAxis2 > 0) { obj["Axis2"] = Axis2.getJson(this, options); } obj["LocalOrigin"] = LocalOrigin.getJson(this, options); if (!double.IsNaN(mScale)) { obj["Scale"] = Scale; } }
//Определяет вид систем координат д/отображения private void InitAxis() //катящегося колеса(Аксис1) и траекторий точек радиуса колеса(Аксис2) { //Колесо Axis1.Axis_Type = 1; Axis1.Pix_type = 3; Axis1.Pix_Size = 2 / XBase; Axis1.x_Base = XBase; Axis1.y_Base = YBase; Axis1.AxisDraw(); //рисуем координатную ось 1 //Траектории Axis2.Axis_Type = 1; Axis2.x_Base = XBase; Axis2.y_Base = YBase; Axis2.Pix_Size = 0; Axis2.AxisDraw(); //рисуем координатную ось 2 }
private void Timer1_Tick(object sender, EventArgs e) { Lambda = 0; while (Lambda < LambdaA) { X = (float)(Fi - Lambda * Sin(Fi)); Y = (float)(1 - Lambda * Cos(Fi)); Axis2.PixDraw(X, Y, Color.Black, 0); Lambda = Lambda + DeltaLambda; } ; Xo = (float)Fi; Yo = 1; //новые координаты точки А Xa = (float)(Fi - LambdaA * Sin(Fi)); Ya = (float)(1 - LambdaA * Cos(Fi)); //рисуем точку траектории в статический буфер Axis1.Pix_type = 1; Axis1.Pix_Size = (float)(0.01 * (YBase / XBase)); Axis1.PixDraw(Xa, Ya, Color.Red, 1); //рисуем колесо в динамический буфер Axis1.Pix_type = 3; Axis1.Pix_Size = 2 / XBase; Axis1.PixDraw(Xo, Yo, Color.Red, 2); //рисуем радиус в динамический буфер Axis1.Pix_color = Color.Blue; Axis1.Line(Xa, Ya, Xo, Yo, 2); //отображаем общую картинку Axis1.DinToPic(); Fi = Fi + DeltaFi; }
/// <summary> /// Writes the coordinate system information in the specified <see cref="XmlWriter"/>. /// </summary> /// <param name="writer">The writer.</param> /// <exception cref="System.ArgumentNullException">writer</exception> internal void Serialize(XmlWriter writer) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } writer.WriteStartElement("Origin"); Origin.Serialize(writer); writer.WriteEndElement(); writer.WriteStartElement("Axis1"); Axis1.Serialize(writer); writer.WriteEndElement(); writer.WriteStartElement("Axis2"); Axis2.Serialize(writer); writer.WriteEndElement(); writer.WriteStartElement("Axis3"); Axis3.Serialize(writer); writer.WriteEndElement(); }
//Create an ellipse given a binding rectangle. public Ellipse(Rectangle _BindingRectangle) { BindingRectangle = _BindingRectangle; Line Diagonal = new Line(BindingRectangle.Vertex1, BindingRectangle.Vertex3); Point CenterOfDiagonal = new Point(((Diagonal.Point1.X + Diagonal.Point2.X) / 2), ((Diagonal.Point1.Y + Diagonal.Point2.Y) / 2)); Point CenterOfRectangleEdge1 = new Point(((BindingRectangle.Vertex1.X + BindingRectangle.Vertex2.X) / 2), ((BindingRectangle.Vertex1.Y + BindingRectangle.Vertex2.Y) / 2)); Point CenterOfRectangleEdge2 = new Point(((BindingRectangle.Vertex2.X + BindingRectangle.Vertex3.X) / 2), ((BindingRectangle.Vertex2.Y + BindingRectangle.Vertex3.Y) / 2)); Point CenterOfRectangleEdge3 = new Point(((BindingRectangle.Vertex3.X + BindingRectangle.Vertex4.X) / 2), ((BindingRectangle.Vertex3.Y + BindingRectangle.Vertex4.Y) / 2)); Point CenterOfRectangleEdge4 = new Point(((BindingRectangle.Vertex4.X + BindingRectangle.Vertex1.X) / 2), ((BindingRectangle.Vertex4.Y + BindingRectangle.Vertex1.Y) / 2)); Line _Axis1 = new Line(CenterOfRectangleEdge1, CenterOfRectangleEdge3); Line _Axis2 = new Line(CenterOfRectangleEdge2, CenterOfRectangleEdge4); Center = CenterOfDiagonal; Vertex1 = CenterOfRectangleEdge1; Vertex2 = CenterOfRectangleEdge2; Vertex3 = CenterOfRectangleEdge3; Vertex4 = CenterOfRectangleEdge4; Axis1 = _Axis1; Axis2 = _Axis2; if (Axis1.ComputeLength() > Axis2.ComputeLength()) { //Axis1 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } else { //Axis2 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Focis are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } }
// called when this entity is added to a stage protected override void OnEnterStage(Stage stage) { base.OnEnterStage(stage); _moveAxis = stage.Game.Controls.RightAnalog; }
/// <summary>Set a value of the vector at a certain component.</summary> public void Set(float value, Axis2 component) { Set(value, (int)component); }
//Create an ellipse given a binding rectangle. public Ellipse(string _name, string _color, Rectangle _BindingRectangle) : base(_name, _color) { BindingRectangle = _BindingRectangle; Line Diagonal = new Line(_name + "'s Diagonal", _color, BindingRectangle.myPoints[0], BindingRectangle.myPoints[2]); Point CenterOfDiagonal = new Point("null", "null", ((Diagonal.myPoints[0].X + Diagonal.myPoints[1].X) / 2), ((Diagonal.myPoints[0].Y + Diagonal.myPoints[1].Y) / 2)); Point CenterOfRectangleEdge1 = new Point("null", "null", ((BindingRectangle.myPoints[0].X + BindingRectangle.myPoints[1].X) / 2), ((BindingRectangle.myPoints[0].Y + BindingRectangle.myPoints[1].Y) / 2)); Point CenterOfRectangleEdge2 = new Point("null", "null", ((BindingRectangle.myPoints[1].X + BindingRectangle.myPoints[2].X) / 2), ((BindingRectangle.myPoints[1].Y + BindingRectangle.myPoints[2].Y) / 2)); Point CenterOfRectangleEdge3 = new Point("null", "null", ((BindingRectangle.myPoints[2].X + BindingRectangle.myPoints[3].X) / 2), ((BindingRectangle.myPoints[2].Y + BindingRectangle.myPoints[3].Y) / 2)); Point CenterOfRectangleEdge4 = new Point("null", "null", ((BindingRectangle.myPoints[3].X + BindingRectangle.myPoints[0].X) / 2), ((BindingRectangle.myPoints[3].Y + BindingRectangle.myPoints[0].Y) / 2)); Line _Axis1 = new Line(_name + "'s _Axis1", _color, CenterOfRectangleEdge1, CenterOfRectangleEdge3); Line _Axis2 = new Line(_name + "'s _Axis2", _color, CenterOfRectangleEdge2, CenterOfRectangleEdge4); Center = CenterOfDiagonal; Vertex1 = CenterOfRectangleEdge1; Vertex2 = CenterOfRectangleEdge2; Vertex3 = CenterOfRectangleEdge3; Vertex4 = CenterOfRectangleEdge4; Axis1 = _Axis1; Axis2 = _Axis2; if (Axis1.ComputeLength() > Axis2.ComputeLength()) { //Axis1 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(_name + "'s Foci2", _color, CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2)) - ((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(_name + "'s Foci2", _color, Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } else { //Axis2 is major axis if (CenterOfRectangleEdge1.X == CenterOfRectangleEdge3.X) { //foci are on the x axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, CenterOfRectangleEdge1.X, Center.Y - FociDistanceFromCenter); Point _foci2 = new Point(_name + "'s Foci2", _color, CenterOfRectangleEdge1.X, Center.Y + FociDistanceFromCenter); Foci1 = _foci1; Foci2 = _foci2; } else { //Focis are on the y axis double FociDistanceFromCenter = Math.Sqrt(((Axis2.ComputeLength() / 2) * (Axis2.ComputeLength() / 2)) - ((Axis1.ComputeLength() / 2) * (Axis1.ComputeLength() / 2))); Point _foci1 = new Point(_name + "'s Foci1", _color, Center.X - FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Point _foci2 = new Point(_name + "'s Foci2", _color, Center.X + FociDistanceFromCenter, CenterOfRectangleEdge1.Y); Foci1 = _foci1; Foci2 = _foci2; } } }
public override double ComputeArea() { return(Math.PI * Axis1.ComputeLength() / 2 * Axis2.ComputeLength() / 2); }
public static string GetActionSet(this Axis2 a) => _GetActionSet(a);