//descriptor parameters /// <summary> /// Create a SIFTDetector using the specific values /// </summary> /// <param name="nOctaves">The number of octaves. Use 4 for default</param> /// <param name="nOctaveLayers">The number of octaves layers. Use 3 for default</param> /// <param name="firstOctave">Use -1 for default</param> /// <param name="threshold">Detector parameter. Use 0.04 / nOctavesLayers / 2.0 as default</param> /// <param name="edgeThreshold">Detector parameter. Use 10.0 as default</param> /// <param name="angleMode">Angle mode</param> /// <param name="magnification">Descriptor parameter. Use 3.0 as default</param> /// <param name="isNormalize">Descriptor parameter. Use true as default</param> /// <param name="recalculateAngles">Descriptor parameter. Use true as default</param> public SIFTDetector( int nOctaves, int nOctaveLayers, int firstOctave, AngleMode angleMode,//common parameters double threshold, double edgeThreshold, //detector parameters double magnification, bool isNormalize, bool recalculateAngles) { _ptr = CvSIFTDetectorCreate(nOctaves, nOctaveLayers, firstOctave, angleMode, threshold, edgeThreshold, magnification, isNormalize, recalculateAngles); }
private static double GetMult(AngleMode From) { return From == AngleMode.deg ? Math.PI / 180d : From == AngleMode.rad ? 1 : 1; }
/// <summary> /// Determine what the given string is and calculate if necessary /// </summary> /// <param name="stringTerm"></param> /// <returns> Type of double? because if the term could not be a number </returns> private static double?ParseTerm(string stringTerm, AngleMode angleMode) { Double tempNum = 0.0; if (Operators.Keys.Contains(stringTerm)) { // Not a value so not added to array but null space is // Null space is to maintain indexs between the two Lists (string, double) return(null); } else if (Functions.Keys.Contains(stringTerm.Split('(')[0])) { // Solve function and place in list return(SolveFunction(stringTerm, angleMode)); } else if (Constants.Keys.Contains(stringTerm)) { // Return Math value return(Constants[stringTerm]); } else if (Double.TryParse(stringTerm, out tempNum)) { // Place value in list return(tempNum); } else { throw new Exception($"Unknown term: '{stringTerm}'"); } }
/// <summary> /// Create a SIFTDetector using the specific values /// </summary> /// <param name="nOctaves">The number of octaves. Use 4 for default</param> /// <param name="nOctaveLayers">The number of octaves layers. Use 3 for default</param> /// <param name="firstOctave">Use -1 for default</param> /// <param name="threshold">Detector parameter. Use 0.04 / nOctavesLayers / 2.0 as default</param> /// <param name="edgeThreshold">Detector parameter. Use 10.0 as default</param> /// <param name="angleMode">Angle mode</param> /// <param name="magnification">Descriptor parameter. Use 3.0 as default</param> /// <param name="isNormalize">Descriptor parameter. Use true as default</param> /// <param name="recalculateAngles">Descriptor parameter. Use true as default</param> public SIFTDetector( int nOctaves, int nOctaveLayers, int firstOctave, AngleMode angleMode, //common parameters double threshold, double edgeThreshold, //detector parameters double magnification, bool isNormalize, bool recalculateAngles) //descriptor parameters { _ptr = CvSIFTDetectorCreate(nOctaves, nOctaveLayers, firstOctave, angleMode, threshold, edgeThreshold, magnification, isNormalize, recalculateAngles); }
public static AngularUnit BuildFromRadianValue(double value, AngleMode mode, AngleRange range) { switch (mode) { case AngleMode.Degree: value = UnitConversion.RadianToDegree(value); break; case AngleMode.Grade: value = UnitConversion.RadianToGrade(value); break; case AngleMode.Radian: break; default: throw new NotImplementedException(); } return(Build(value, mode, range)); }
public void SetAngleMode(AngleMode mode) { _jsRuntime.InvokeVoid( _p5InvokeFunction, "angleMode", AngleModeToString(mode) ); }
public TweenData_Transform_EulerRotationFixed(Transform inTransform, Vector3 inTarget, Space inSpace, Axis inAxis, AngleMode inMode) { m_Transform = inTransform; m_Target = inTarget; m_Space = inSpace; m_Axis = inAxis; m_Mode = inMode; }
public ExpressionParser(string expression, AngleMode angleMode) { AngleMode = angleMode; Expression = expression; InfixTokens = Tokenize(expression); PostfixTokens = InfixToPostfix(InfixTokens); Result = Calculate(PostfixTokens); }
public static Vector3 ShortAngle(Vector3 angle, AngleMode mode) { return(new Vector3( ShortAngle(angle.x, mode), ShortAngle(angle.y, mode), ShortAngle(angle.z, mode) )); }
/// <summary> /// コンストラクタ /// </summary> public Calculator(AngleMode angleMode) { var angleFuncTable = (angleMode == AngleMode.Radian ? RadianFuncTable : (angleMode == AngleMode.Degree ? DegreeFuncTable : EmptyFuncTable)); this.parser = CreateParser(angleMode); this.constTable = DefaultConstTable; this.funcTable = DefaultFuncTable.Concat(angleFuncTable).ToArray(); }
/// <summary> /// Convert to the short angle /// Taken from https://github.com/greensock/GreenSock-JS/blob/master/src/uncompressed/plugins/DirectionalRotationPlugin.js /// </summary> /// <param name="angle"></param> /// <param name="mode">Degress or Radians</param> /// <returns></returns> public static float ShortAngle(float angle, AngleMode mode) { var limit = (mode == AngleMode.Radians) ? Mathf.PI * 2f : 360; var a = angle % limit; if (a != a % (limit / 2f)) { a = (a <= 0) ? a + limit : a - limit; } return(a); }
/// <summary> /// Rotates an object in the drawing. /// </summary> /// <param name="rotationAxis">Vector representing the custom axis around /// which the rotation will take place.</param> /// <param name="mode">States if the angle entered is in degrees or radians.</param> public static void Rotate(Entity entity, Point3d basePoint, double rotationAngle, Vector3d rotationAxis, AngleMode mode) { if (mode == AngleMode.Degrees) { rotationAngle = rotationAngle * Math.PI / 180; } Matrix3d rotateMatrix = Matrix3d.Rotation(rotationAngle, rotationAxis, basePoint); entity.TransformBy(rotateMatrix); }
/// <summary> /// 新規にパーサーを作成します。 /// </summary> private Grammar CreateParser(AngleMode angleMode) { var sDelim = Scanners.IsWhitespaces().Many_(); var OPs = Terms.GetOperatorsInstance( "+", "-", "**", "*", "/", "%", "(", ")", ",", "#"); var lToken = OPs.Lexer | Lexers.LexDecimal() | Lexers.LexWord(); var lexeme = Lexers.Lexeme(sDelim, lToken).FollowedBy(Parsers.Eof()); var pNumber = Terms.OnDecimal((from, len, s) => double.Parse(s)); var pWord = Terms.OnWord((from, len, s) => s); Terms.FromSimpleToken <string, string>((from, len, s) => s); var pPlus = GetOperator(OPs, "+", new Binary((a, b) => (a + b))); var pMinus = GetOperator(OPs, "-", new Binary((a, b) => (a - b))); var pMul = GetOperator(OPs, "*", new Binary((a, b) => (a * b))); var pDiv = GetOperator(OPs, "/", new Binary((a, b) => (a / b))); var pMod = GetOperator(OPs, "%", new Binary((a, b) => (a % b))); var pPow = GetOperator(OPs, "**", new Binary((a, b) => Math.Pow(a, b))); var pNone = GetOperator(OPs, "+", new Unary(n => n)); var pNeg = GetOperator(OPs, "-", new Unary(n => - n)); var opTable = new OperatorTable <double>() .Infixl(pPlus, 10) .Infixl(pMinus, 10) .Infixl(pMul, 20) .Infixl(pDiv, 20) .Infixl(pMod, 20) .Infixr(pPow, 30) .Prefix(pNone, 40) .Prefix(pNeg, 40); var pLParen = OPs.GetParser("("); var pRParen = OPs.GetParser(")"); var pComma = OPs.GetParser(new string[] { ",", "#" }); var lazyExpr = new Grammar[1]; var pLazyExpr = Parsers.Lazy <double>(() => lazyExpr[0]); var pArg = pLazyExpr.SepEndBy(pComma).Between(pLParen, pRParen) | pLParen.Seq(pRParen).Seq(Parsers.Return(new double[0])); var pTerm = pLazyExpr.Between(pLParen, pRParen) | pWord.And(pArg.Optional(), new Map <string, double[], double>(CalcFunc)) | pNumber; var pExpr = Expressions.BuildExpressionParser(pTerm, opTable); lazyExpr[0] = pExpr; return(Parsers.ParseTokens(lexeme, pExpr.FollowedBy(Parsers.Eof()), "calculator")); }
public void TestTrigonometricIntegrate(string expression, AngleMode mode, double from, double to, double expected) { NumberMath.AngleMode = mode; ExpressionParser parser = new ExpressionParser(); IExpression expr = parser.Parse(expression, Mocks.CreateVariableMock()); INumber f = (Number)from; INumber t = (Number)to; Number result = expr.Integrate("x", f, t) as Number; AreEqual(expected, result, 1E-2); }
/// <summary> /// Performs the function named before the "(" using the value/expression between the "(" and ")" /// </summary> /// <param name="stringTerm"></param> /// <returns></returns> private static double SolveFunction(string stringTerm, AngleMode angleMode) { string[] parts = stringTerm.Split(new char[] { '(' }, 2); string funcName = parts[0]; double value = Resolve(parts[1].Substring(0, parts[1].Length - 1)); string[] trigFunctions = new string[] { "sin", "cos", "tan", "asin", "acos", "atan" }; if (trigFunctions.Contains(funcName)) { value = ConvertToRad(value, angleMode); } return(Functions[funcName](value)); }
/// <summary> /// Entry point into parser. Default Angle mode to Rad. /// </summary> /// <param name="expressionStr"></param> /// <returns></returns> public static double Resolve(string expressionStr, AngleMode angleMode = AngleMode.Rad) { if (!Validation.Brackets(expressionStr)) { throw new Exception("Invalid brackets"); } if (expressionStr.Length == 0) { // There are no terms so default to 0 return(0); } string[] expressionAry = Clean(expressionStr); return(Calculate(expressionAry.ToList(), angleMode)); }
/// <summary> /// Prompts the user to input an angle. /// </summary> /// <param name="message">Message to display in the command line.</param> /// <returns>The angle input by the user.</returns> public static double GetAngle(string message, ref PromptStatus status, AngleMode mode) { PromptAngleOptions options = new PromptAngleOptions(System.Environment.NewLine + message); Editor command = Application.DocumentManager.MdiActiveDocument.Editor; PromptDoubleResult result = command.GetAngle(options); status = result.Status; double angle = result.Value; if (mode == AngleMode.Degrees) { angle = angle * 180 / Math.PI; } return(angle); }
private void InitFormat(IFrame frame) { MultipleChoiceSetting formattingSystem = frame.GetSetting("Formatting.System") as MultipleChoiceSetting; if (formattingSystem != null && formattingSystem.CurrentSelection >= 0) { displayCoordinateSystem = (DisplayCoordinateSystem)formattingSystem.CurrentSelection; } else { displayCoordinateSystem = DisplayCoordinateSystem.local; } MultipleChoiceSetting formattingZValue = frame.GetSetting("Formatting.Coordinate.ZValue") as MultipleChoiceSetting; if (formattingZValue != null && formattingZValue.CurrentSelection >= 0) { displayZComponent = formattingZValue.CurrentSelection == 0; } else { displayZComponent = true; } alwaysAbsoluteCoordinateSystem = false; alwaysZComponent = false; displayMode = (DisplayMode)frame.GetIntSetting("Formatting.Vector.Mode", 0); numberFormatInfo = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone(); int decsym = Settings.GlobalSettings.GetIntValue("Formatting.Decimal", 0); // Systemeinstellung | Punkt | Komma // wenn 0, dann unverändert if (decsym == 1) { numberFormatInfo.NumberDecimalSeparator = "."; } else if (decsym == 2) { numberFormatInfo.NumberDecimalSeparator = ","; } numberFormatInfo.NumberDecimalDigits = frame.GetIntSetting("Formatting.Coordinate.Digits", 3); componentsDigits = frame.GetIntSetting("Formatting.Coordinate.ComponentsDigits", 3); angleMode = (AngleMode)frame.GetIntSetting("Formatting.Angle.Mode", 0); angleDigits = frame.GetIntSetting("Formatting.Angle.Digits", 3); this.Frame = frame; }
/// <summary> /// Rotates an object in the drawing. /// </summary> /// <param name="rotationAngle">Angle in decimal degrees.</param> /// <param name="rotationAxis">X, Y, or Z axis around wich the rotation will take place.</param> /// <remarks>This method performs a 2D rotation around the specified axis.</remarks> public static void Rotate(Entity entity, Point3d basePoint, double rotationAngle, Axis rotationAxis, AngleMode mode) { // Default case is rotation around de Z-axis. Vector3d rotateVector = new Vector3d(0, 0, 1); switch (rotationAxis) { case Axis.X: rotateVector = new Vector3d(1, 0, 0); break; case Axis.Y: rotateVector = new Vector3d(0, 1, 0); break; } Rotate(entity, basePoint, rotationAngle, rotateVector, mode); }
private void btnAngleMode_Click(object sender, EventArgs e) { switch (angleMode) { case AngleMode.Rad: angleMode = AngleMode.Deg; break; case AngleMode.Deg: angleMode = AngleMode.Grad; break; case AngleMode.Grad: angleMode = AngleMode.Rad; break; } btnAngleMode.Text = angleMode.ToString().ToUpper(); }
internal static double ConvertToRad(double value, AngleMode angleMode) { if (angleMode == AngleMode.Rad) { return(value); } if (angleMode == AngleMode.Deg) { return(value * (Math.PI / 180)); } if (angleMode == AngleMode.Grad) { return(value * (Math.PI / 200)); } throw new Exception("Unknown angle mode."); }
public static AngularUnit Build(double value, AngleMode mode, AngleRange range) { switch (mode) { case AngleMode.Degree: return(new Degree(value, range)); case AngleMode.Grade: return(new Grade(value, range)); case AngleMode.Radian: return(new Radian(value, range)); default: throw new NotImplementedException(); } }
/// <summary> /// The cleaned list of terms are now calculated following the BIDMAS order of precedence /// </summary> /// <param name="expressionList">A list of strings split into there individual operators, functions and operands </param> /// <returns></returns> private static double Calculate(List <string> expressionList, AngleMode angleMode) { if (expressionList.Count % 2 == 0) { // Number of terms must be odd to be valid throw new Exception("Invalid expression"); } List <double?> values = new List <double?>(); // Parse and populate values into list performing any functions (and brackets) along the way foreach (string stringTerm in expressionList) { values.Add(ParseTerm(stringTerm, angleMode)); } // Perform operations in order of array (_IDM__) ignoring AS List <string> operatorsToCalculate = Operators.Keys.ToList().GetRange(0, Operators.Count - 2); foreach (string operation in operatorsToCalculate) { while (expressionList.Contains(operation)) { SolveOperation(operation, ref expressionList, ref values); } } // Perform +, - operations from left to right while (expressionList.Contains("+") || expressionList.Contains("-")) { SolveOperation(expressionList[1], ref expressionList, ref values); } if (values[0].Value.Equals(Double.NaN)) // || Double.IsInfinity(values[0].Value)) { throw new Exception("Invalid input"); } return(values[0].Value); }
public void SetAngleMode(AngleMode mode) { var angleMode = ""; switch (mode) { case AngleMode.Degrees: angleMode = "degrees"; break; case AngleMode.Radians: angleMode = "radians"; break; default: throw new Exception("Invalid AngleMode"); } _jsRuntime.InvokeVoid( _p5InvokeFunction, "angleMode", angleMode ); }
/// <summary> /// Distance between 2 points on the surface of a sphere. /// </summary> /// <param name="longlat1">First point in longitude / latitude</param> /// <param name="longlat2">Second point in longitude / latitude</param> /// <param name="R">Radius of the sphere (default is the radius of Earth in meters)</param> /// <param name="anglemode">Angle unit mode of the input</param> /// <returns>The distance value</returns> public static double DistanceOnSurface(Vector2 longlat1, Vector2 longlat2, double R = 6371e3, AngleMode anglemode = AngleMode.Degrees) { var lon1 = longlat1.X; var lat1 = longlat1.Y; var lon2 = longlat2.X; var lat2 = longlat2.Y; var am = 1.0; switch (anglemode) { case AngleMode.Degrees: am = VMath.DegToRad; break; case AngleMode.Cycles: am = VMath.CycToRad; break; } var φ1 = lat1 * am; var φ2 = lat2 * am; var Δφ = (lat2 - lat1) * am; var Δλ = (lon2 - lon1) * am; var a = Math.Sin(Δφ / 2) * Math.Sin(Δφ / 2) + Math.Cos(φ1) * Math.Cos(φ2) * Math.Sin(Δλ / 2) * Math.Sin(Δλ / 2); var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); return(R * c); }
/// <summary>Converts a world position to an angle around the origin.</summary> /// <returns>Angle between the point and the grid's "right" axis.</returns> /// <param name="worldPoint">Point in world space.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method returns which angle around the grid a given point in world space has. public float World2Angle(Vector3 worldPoint, AngleMode mode = AngleMode.radians) { return(WorldToPolar(worldPoint)[idx[1]] * (mode == AngleMode.radians ? 1.0f : Mathf.Rad2Deg)); }
/// <summary>Converts an angle around the origin to a rotation.</summary> /// <returns>Rotation quaternion which rotates around the origin by <paramref name="angle"/>.</returns> /// <param name="angle">Angle in either radians or degrees.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method returns a quaternion which represents a rotation within the /// grid. The result is a combination of the grid's own rotation and the /// rotation from the angle. Since we use an angle, this method is more /// suitable for polar coordinates than grid coordinates. See <see /// cref="Sector2Rotation"/> for a similar method that uses sectors. public Quaternion Angle2Rotation(float angle, AngleMode mode = AngleMode.radians) { return(Quaternion.AngleAxis(angle * (mode == AngleMode.radians ? Mathf.Rad2Deg : 1.0f), locUnits[idx[2]] * (gridPlane == GridPlane.XY ? 1.0f : -1.0f)) * _Transform.rotation); }
/// <summary>Converts a sector to the corresponding angle coordinate (radians or degree).</summary> /// <returns>Angle value of the sector.</returns> /// <param name="sector">Sector number.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method takes in a sector coordinate and returns the corresponding /// angle around the origin. If the sector exceeds the amount of sectors of /// the grid it wraps around, negative sectors are automatically subtracted /// from the maximum. /// /// <example>Let's take a grid with six sectors for example, then one /// sector has an angle of 360° / 6 = 60°, so a 2.25 sector corresponds to /// an angle of 2.25 * 60° = 135°.</example> public float Sector2Angle(float sector, AngleMode mode = AngleMode.radians) { sector = Float2Sector(sector); return(sector * angle * (mode == AngleMode.degrees ? Mathf.Rad2Deg : 1.0f)); }
/// <summary>Converts an angle (radians or degree) to the corresponding sector coordinate.</summary> /// <returns>Sector value of the angle.</returns> /// <param name="angle">Angle in either radians or degress.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method takes in an angle and returns in which sector the angle /// lies. If the angle exceeds 2π or 360° it wraps around, nagetive angles /// are automatically subtracted from 2π or 360°. /// /// <example>Let's take a grid with six sectors for example, then one /// sector has an angle of 360° / 6 = 60°, so a 135° angle corresponds to a /// sector value of 130° / 60° = 2.25.</example> public float Angle2Sector(float angle, AngleMode mode = AngleMode.radians) { angle = Float2Rad(angle * (mode == AngleMode.degrees ? Mathf.Deg2Rad : 1.0f)); return(angle / this.angle * (mode == AngleMode.degrees ? Mathf.Rad2Deg : 1.0f)); }
/// <summary>Converts an angle (radians or degree) to the corresponding sector coordinate.</summary> /// <returns>Sector value of the angle.</returns> /// <param name="angle">Angle in either radians or degress.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method takes in an angle and returns in which sector the angle /// lies. If the angle exceeds 2π or 360° it wraps around, nagetive angles /// are automatically subtracted from 2π or 360°. /// /// <example>Let's take a grid with six sectors for example, then one /// sector has an angle of 360° / 6 = 60°, so a 135° angle corresponds to a /// sector value of 130° / 60° = 2.25.</example> public float Angle2Sector(float angle, AngleMode mode = AngleMode.radians) { angle = Float2Rad(angle * (mode == AngleMode.degrees ? Mathf.Deg2Rad : 1.0f)); return angle / this.angle * (mode == AngleMode.degrees ? Mathf.Rad2Deg : 1.0f); }
/// <summary>Converts a sector to the corresponding angle coordinate (radians or degree).</summary> /// <returns>Angle value of the sector.</returns> /// <param name="sector">Sector number.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method takes in a sector coordinate and returns the corresponding /// angle around the origin. If the sector exceeds the amount of sectors of /// the grid it wraps around, negative sectors are automatically subtracted /// from the maximum. /// /// <example>Let's take a grid with six sectors for example, then one /// sector has an angle of 360° / 6 = 60°, so a 2.25 sector corresponds to /// an angle of 2.25 * 60° = 135°.</example> public float Sector2Angle(float sector, AngleMode mode = AngleMode.radians) { sector = Float2Sector(sector); return sector * angle * (mode == AngleMode.degrees ? Mathf.Rad2Deg : 1.0f); }
private void frmMain_Load(object sender, EventArgs e) { Text = "Calculator"; lblMain = CreateLabel("0", ContentAlignment.MiddleRight, mainLabelFont); lblMemory = CreateLabel("M", ContentAlignment.MiddleLeft, mainLabelFont); lblTemp = CreateLabel("", ContentAlignment.BottomRight, tempLabelFont); lblMemory.Visible = false; MyPanel mainPanel = new MyPanel(DockStyle.Fill, new Padding(4), Color.Transparent); MyTableLayoutPanel mainContainer = new MyTableLayoutPanel(7, 10, DockStyle.Fill, Color.White); mainContainer.SetRowDimension(SizeType.Percent, 20, 13, 13, 13, 13, 13, 13); mainContainer.SetColumnDimension(SizeType.Percent, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10); mainContainer.SetGradientBackground(calcColor2, calcColor1, 90f); MyTableLayoutPanel displayPanel = new MyTableLayoutPanel(2, 2, DockStyle.Fill, new Padding(10), Color.Transparent); displayPanel.SetBorderAndGradientBackground(new Pen(calcBorderColor, 2), calcColor1, calcColor2, 90f); displayPanel.SetRowDimension(SizeType.Percent, 30, 70); displayPanel.SetColumnDimension(SizeType.Percent, 10, 90); displayPanel.Controls.Add(lblTemp, 1, 0); displayPanel.Controls.Add(lblMain, 1, 1); displayPanel.Controls.Add(lblMemory, 0, 0); displayPanel.SetRowSpan(lblMemory, 2); mainContainer.Controls.Add(displayPanel, 0, 0); mainContainer.SetColumnSpan(displayPanel, 10); MyTableLayoutPanel degRadGradPanel = new MyTableLayoutPanel(1, 3, DockStyle.Fill, new Padding(3)); degRadGradPanel.SetColumnDimension(SizeType.Percent, 36, 36, 27); degRadGradPanel.SetBorder(new Pen(calcBorderColor, 2)); RadioButton degButton = CreateRadioButton("Degrees"); RadioButton radButton = CreateRadioButton("Radians", true); RadioButton gradButton = CreateRadioButton("Gradians"); degButton.Click += (s, args) => angleMode = AngleMode.Degree; radButton.Click += (s, args) => angleMode = AngleMode.Radian; gradButton.Click += (s, args) => angleMode = AngleMode.Gradient; degRadGradPanel.Controls.Add(degButton, 0, 0); degRadGradPanel.Controls.Add(radButton, 1, 0); degRadGradPanel.Controls.Add(gradButton, 2, 0); mainContainer.Controls.Add(degRadGradPanel, 0, 1); mainContainer.SetColumnSpan(degRadGradPanel, 5); Button btnMc = CreateButton("MC"); Button btnMr = CreateButton("MR"); Button btnMs = CreateButton("MS"); Button btnMp = CreateButton("M+"); Button btnMm = CreateButton("M-"); mainContainer.Controls.Add(btnMc, 5, 1); mainContainer.Controls.Add(btnMr, 6, 1); mainContainer.Controls.Add(btnMs, 7, 1); mainContainer.Controls.Add(btnMp, 8, 1); mainContainer.Controls.Add(btnMm, 9, 1); MyPanel emptyPanel = new MyPanel(DockStyle.Fill, Padding.Empty, Color.Transparent); emptyPanel.SetBorder(new Pen(calcBorderColor, 1)); Button btnE = CreateButton("e"); Button btnLn = CreateButton("ln"); Button btnRnd = CreateButton("Rnd"); Button btnEToX = CreateButton("eⁿ"); Button btnBksp = CreateButton("←"); Button btnCE = CreateButton("CE"); Button btnC = CreateButton("C"); Button btnPlusMinus = CreateButton("±"); Button btnSqrt = CreateButton("√"); mainContainer.Controls.Add(emptyPanel, 0, 2); mainContainer.Controls.Add(btnE, 1, 2); mainContainer.Controls.Add(btnLn, 2, 2); mainContainer.Controls.Add(btnRnd, 3, 2); mainContainer.Controls.Add(btnEToX, 4, 2); mainContainer.Controls.Add(btnBksp, 5, 2); mainContainer.Controls.Add(btnCE, 6, 2); mainContainer.Controls.Add(btnC, 7, 2); mainContainer.Controls.Add(btnPlusMinus, 8, 2); mainContainer.Controls.Add(btnSqrt, 9, 2); Button btnInt = CreateButton("Int"); Button btnSinh = CreateButton("sinh"); Button btnSin = CreateButton("sin"); Button btnXsquare = CreateButton("x²"); Button btnFact = CreateButton("n!"); Button btn7 = CreateButton("7"); Button btn8 = CreateButton("8"); Button btn9 = CreateButton("9"); Button btnDiv = CreateButton("/"); Button btnPercent = CreateButton("%"); mainContainer.Controls.Add(btnInt, 0, 3); mainContainer.Controls.Add(btnSinh, 1, 3); mainContainer.Controls.Add(btnSin, 2, 3); mainContainer.Controls.Add(btnXsquare, 3, 3); mainContainer.Controls.Add(btnFact, 4, 3); mainContainer.Controls.Add(btn7, 5, 3); mainContainer.Controls.Add(btn8, 6, 3); mainContainer.Controls.Add(btn9, 7, 3); mainContainer.Controls.Add(btnDiv, 8, 3); mainContainer.Controls.Add(btnPercent, 9, 3); Button btnDms = CreateButton("dms"); Button btnCosh = CreateButton("cosh"); Button btnCos = CreateButton("cos"); Button btnXPowerN = CreateButton("xⁿ"); Button btnYRootX = CreateButton("ⁿ√x"); Button btn4 = CreateButton("4"); Button btn5 = CreateButton("5"); Button btn6 = CreateButton("6"); Button btnMult = CreateButton("*"); Button btn1ByX = CreateButton("1/x"); mainContainer.Controls.Add(btnDms, 0, 4); mainContainer.Controls.Add(btnCosh, 1, 4); mainContainer.Controls.Add(btnCos, 2, 4); mainContainer.Controls.Add(btnXPowerN, 3, 4); mainContainer.Controls.Add(btnYRootX, 4, 4); mainContainer.Controls.Add(btn4, 5, 4); mainContainer.Controls.Add(btn5, 6, 4); mainContainer.Controls.Add(btn6, 7, 4); mainContainer.Controls.Add(btnMult, 8, 4); mainContainer.Controls.Add(btn1ByX, 9, 4); Button btnPi = CreateButton("Pi"); Button btnTanh = CreateButton("tanh"); Button btnTan = CreateButton("tan"); Button btnXCube = CreateButton("x³"); Button btnThirdRootX = CreateButton("³√x"); Button btn1 = CreateButton("1"); Button btn2 = CreateButton("2"); Button btn3 = CreateButton("3"); Button btnMinus = CreateButton("-"); Button btnEquals = CreateButton("="); mainContainer.Controls.Add(btnPi, 0, 5); mainContainer.Controls.Add(btnTanh, 1, 5); mainContainer.Controls.Add(btnTan, 2, 5); mainContainer.Controls.Add(btnXCube, 3, 5); mainContainer.Controls.Add(btnThirdRootX, 4, 5); mainContainer.Controls.Add(btn1, 5, 5); mainContainer.Controls.Add(btn2, 6, 5); mainContainer.Controls.Add(btn3, 7, 5); mainContainer.Controls.Add(btnMinus, 8, 5); mainContainer.Controls.Add(btnEquals, 9, 5); mainContainer.SetRowSpan(btnEquals, 2); CheckBox btnFE = CreateCheckBox("F-E"); Button btnExp = CreateButton("Exp"); Button btnMod = CreateButton("Mod"); Button btnLog = CreateButton("log"); Button btn10ToX = CreateButton("10ⁿ"); Button btn0 = CreateButton("0"); Button btnDot = CreateButton("."); Button btnPlus = CreateButton("+"); mainContainer.Controls.Add(btnFE, 0, 6); mainContainer.Controls.Add(btnExp, 1, 6); mainContainer.Controls.Add(btnMod, 2, 6); mainContainer.Controls.Add(btnLog, 3, 6); mainContainer.Controls.Add(btn10ToX, 4, 6); mainContainer.Controls.Add(btn0, 5, 6); mainContainer.SetColumnSpan(btn0, 2); mainContainer.Controls.Add(btnDot, 7, 6); mainContainer.Controls.Add(btnPlus, 8, 6); mainPanel.Controls.Add(mainContainer); this.Controls.Add(mainPanel); btnBksp.Click += (s, args) => { if (lblMain.Text.Length == 1) { lblMain.Text = "0"; } else { lblMain.Text = lblMain.Text.Substring(0, lblMain.Text.Length - 1); } }; btnCE.Click += (s, args) => { lblMain.Text = "0"; if (isLastUnary) { lblTemp.Text = unaryTemp; } unaryTemp = ""; unaryExp = ""; }; btnC.Click += (s, args) => { currentFunction = Function.None; lblMain.Text = "0"; lblTemp.Text = ""; unaryExp = ""; unaryTemp = ""; }; btnEquals.Click += (s, args) => { current = Convert.ToDouble(lblMain.Text); EvaluatePending(); lblTemp.Text = ""; currentFunction = Function.None; isOverwrite = true; }; btnDot.Click += (s, args) => { if (!isDecimal) { MainInput("."); } isDecimal = true; }; btnPlusMinus.Click += (s, args) => { if (lblMain.Text[0] == '-') { lblMain.Text = lblMain.Text.Substring(1); } else { lblMain.Text = '-' + lblMain.Text; } }; btnMs.Click += (s, args) => { userMemory = Convert.ToDouble(lblMain.Text); lblMemory.Visible = true; isOverwrite = true; isMemorySet = true; }; btnMc.Click += (s, args) => { userMemory = 0; lblMemory.Visible = false; isMemorySet = false; }; btnMr.Click += (s, args) => { lblMain.Text = userMemory.ToString(); isOverwrite = true; }; btnMp.Click += (s, args) => { if (isMemorySet) { userMemory += Convert.ToDouble(lblMain.Text); lblMain.Text = userMemory.ToString(); isOverwrite = true; } }; btnMm.Click += (s, args) => { if (isMemorySet) { userMemory -= Convert.ToDouble(lblMain.Text); lblMain.Text = userMemory.ToString(); isOverwrite = true; } }; btnFE.Click += (s, args) => { isScientific = btnFE.Checked; FunctionInputUnary(Function.Exponential); isOverwrite = true; }; btn1.Click += (s, args) => MainInput("1"); btn2.Click += (s, args) => MainInput("2"); btn3.Click += (s, args) => MainInput("3"); btn4.Click += (s, args) => MainInput("4"); btn5.Click += (s, args) => MainInput("5"); btn6.Click += (s, args) => MainInput("6"); btn7.Click += (s, args) => MainInput("7"); btn8.Click += (s, args) => MainInput("8"); btn9.Click += (s, args) => MainInput("9"); btn0.Click += (s, args) => MainInput("0"); btnPlus.Click += (s, args) => FunctionInput(Function.Addition); btnMinus.Click += (s, args) => FunctionInput(Function.Subtraction); btnMult.Click += (s, args) => FunctionInput(Function.Multiplication); btnDiv.Click += (s, args) => FunctionInput(Function.Division); btnMod.Click += (s, args) => FunctionInput(Function.Mod); btnXPowerN.Click += (s, args) => FunctionInput(Function.XToY); btnYRootX.Click += (s, args) => FunctionInput(Function.YRootX); btn10ToX.Click += (s, args) => FunctionInputUnary(Function.Power10); btnLog.Click += (s, args) => FunctionInputUnary(Function.Log10); btnExp.Click += (s, args) => FunctionInputUnary(Function.Exponential); btnThirdRootX.Click += (s, args) => FunctionInputUnary(Function.ThirdRootX); btnXCube.Click += (s, args) => FunctionInputUnary(Function.XCube); btnTanh.Click += (s, args) => FunctionInputUnary(Function.TanH); btnTan.Click += (s, args) => FunctionInputUnary(Function.Tan); btnPi.Click += (s, args) => FunctionInputUnary(Function.Pi); btnCosh.Click += (s, args) => FunctionInputUnary(Function.CosH); btnCos.Click += (s, args) => FunctionInputUnary(Function.Cos); btnSinh.Click += (s, args) => FunctionInputUnary(Function.SinH); btnSin.Click += (s, args) => FunctionInputUnary(Function.Sin); btnDms.Click += (s, args) => FunctionInputUnary(Function.Dms); btnFact.Click += (s, args) => FunctionInputUnary(Function.Factorial); btnXsquare.Click += (s, args) => FunctionInputUnary(Function.XSquare); btnInt.Click += (s, args) => FunctionInputUnary(Function.Int); btnLn.Click += (s, args) => FunctionInputUnary(Function.LogE); btnRnd.Click += (s, args) => FunctionInputUnary(Function.Random); btnEToX.Click += (s, args) => FunctionInputUnary(Function.EToX); btnE.Click += (s, args) => FunctionInputUnary(Function.E); btn1ByX.Click += (s, args) => FunctionInputUnary(Function.OneByX); btnSqrt.Click += (s, args) => FunctionInputUnary(Function.SquareRoot); btnPercent.Click += (s, args) => FunctionInputUnary(Function.Percent); }
static void Main(string[] args) { /****************************** * CALCULATOR CODE ******************************/ double ANGLE_MULT = GetMult(Mode); Stopwatch parse = new Stopwatch(), solve = new Stopwatch(); Func<object[], int, int, Vector> Str2V = (o, l, r) => new DenseVector(o.Where((x, i) => l <= i && i <= r).Select(d => D(d)).ToArray()); Func<object[], int, Vector> Str2D = (o, i) => Str2V(o, i, i); //Func<object[], Vector> Str2A = (o) => Str2V(o, 0, o.Length - 1); Func<double, Vector> DefineConstant = (d) => new DenseVector(new double[]{d}); Function[] Funcs = new Function[] { //OPERATORS new Function(d => Str2V(d,0,1), 2,2,@"[{0},{1}]",@"\[(.+),(.+)\]") ,new Function(d => Vec(Str2D(d,0)[0] * Math.Cos(Str2D(d,1)[0]), Str2D(d,0)[0] * Math.Sin(Str2D(d,1)[0])), 2,2,@"[{0},{1}]",@"\[(.+),<(.+)\]") ,new Function(d => Str2D(d,0).Add(Str2D(d,1)), 2,1,"{0}+{1}",@"(.+)[+](.+)") ,new Function(d => Str2D(d,0).Subtract(Str2D(d,1)), 2,1,"{0}-{1}",@"(.+)[-](.+)") ,new Function(d => Str2D(d,0).PointwiseMultiply(Str2D(d,1)), 2,2,"{0}*{1}",@"(.+)[*](.+)") ,new Function(d => Str2D(d,0).PointwiseDivide(Str2D(d,1)), 2,2,"{0}/{1}",@"(.+)[/](.+)") ,new Function(d => Str2D(d,0), 1,5,"({0})",@"\((.+)\)") //FUNCTIONS ,new Function(d => Vec(d.Select(i => Math.Sin(D(i) * ANGLE_MULT)).ToArray()), 1,4,"SIN({0})",@"sin\((.+)\)") ,new Function(d => Vec(d.Select(i => Math.Cos(D(i) * ANGLE_MULT)).ToArray()), 1,4,"COS({0})",@"cos\((.+)\)") ,new Function(d => Vec(d.Select(i => Math.Tan(D(i) * ANGLE_MULT)).ToArray()), 1,4,"TAN({0})",@"tan\((.+)\)") ,new Function(d => Vec(d.Select(i => Math.Asin(D(i) * ANGLE_MULT)).ToArray()), 1,4,"ASIN({0})",@"asin\((.+)\)") ,new Function(d => Vec(d.Select(i => Math.Acos(D(i) * ANGLE_MULT)).ToArray()), 1,4,"ACOS({0})",@"acos\((.+)\)") ,new Function(d => Vec(d.Select(i => Math.Atan(D(i) * ANGLE_MULT)).ToArray()), 1,4,"ATAN({0})",@"atan\((.+)\)") ,new Function(d => Vec(d.Select(i => Math.Sqrt(D(i) * ANGLE_MULT)).ToArray()), 1,4,"SQRT({0})",@"sqrt\((.+)\)") ,new Function(d => { Variable.SetVariable(d[0].ToString(), d[1]); return null;}, 2, 4, "{{{0}}} set to {1}", @"set\((\w+)=(.+)\)") ,new Function(d => {Variable.ClearVariables(); return null;}, 0, 4, "Variables Cleared", "clear") //CONSTANTS ,new Function(d => DefineConstant(Math.PI),0,5,"PI","pi") //SETTINSG ,new Function(d => { try { Mode = (AngleMode)Enum.Parse(typeof(AngleMode), d[0].ToString(), true); } catch (ArgumentException) { return d[0].ToString() + " is an invalid mode. Use one of the following: " + string.Join(",", Enum.GetNames(typeof(AngleMode))); } ANGLE_MULT = GetMult(Mode); return "Mode Set"; }, 1,5,"MODE={0}",@"mode=(\w+)") }; //char[] Alphabet = Enumerable.Range(97, 26).Select<int,char>(i => (char)i).ToArray(); Console.WriteLine("Currently supported functions:"); foreach (Function f in Funcs) Console.WriteLine(f.GetPrintFormat, 'a','b','c'); Console.WriteLine(); Console.WriteLine("Please input a math function of some sort"); Function.FLAGAssumeStrayString = true; Function.RegConstant = new Function(v => double.Parse(v[0].ToString()), 0, int.MaxValue, "{0}", @"((?:\d+\.?\d*?)|(?:\d*\.?\d+))"); double junkDoub; Constant.sIsActuallyConstant = (s) => double.TryParse(s, out junkDoub) ? null : s; do { string input = Console.ReadLine(); parse.Restart(); FuncInst Result = Function.Parse(input, Funcs); parse.Stop(); Console.WriteLine("Here's what I think you were saying:"); Console.WriteLine(Result == null ? "NULL" : Result.ToString()); if (Result != null) { Console.WriteLine("Which equals:"); solve.Restart(); var ans = Result.Solve(); solve.Stop(); Console.WriteLine((ans ?? "No response").ToString()); Console.WriteLine("Parse time: {0} ({1} ms)\t\t\tSolve time: {2} ({3} ms)", parse.ElapsedTicks, parse.ElapsedMilliseconds, solve.ElapsedTicks, solve.ElapsedMilliseconds); } Console.WriteLine("Try another one"); } while (true); //Function[] Funcs = new Function[]{ // new Function(o => null, 1, 2, "{0};", "(.+);"), // new Function(o => {Console.WriteLine(o[0].ToString());return null;}, 1, 1, "write({0})", @"write\((.+)\)"), // new Function(o => (string)o[0] + (string)o[1], 2, 1, "cat({0},{1})", @"cat\((.+),(.+)\)") //}; //FuncInst Result = Function.Parse(Console.ReadLine(), Funcs); //Console.WriteLine(Result.Solve()); //Console.ReadLine(); }
/// <summary>Converts an angle around the origin to a rotation.</summary> /// <returns>Rotation quaternion which rotates around the origin by <paramref name="angle"/>.</returns> /// <param name="angle">Angle in either radians or degrees.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method returns a quaternion which represents a rotation within the /// grid. The result is a combination of the grid's own rotation and the /// rotation from the angle. Since we use an angle, this method is more /// suitable for polar coordinates than grid coordinates. See <see /// cref="Sector2Rotation"/> for a similar method that uses sectors. public Quaternion Angle2Rotation(float angle, AngleMode mode = AngleMode.radians) { return Quaternion.AngleAxis(angle * (mode == AngleMode.radians ? Mathf.Rad2Deg : 1.0f), locUnits[idx[2]] * (gridPlane == GridPlane.XY ? 1.0f : -1.0f)) * _Transform.rotation; }
private static extern IntPtr CvSIFTDetectorCreate( int nOctaves, int nOctaveLayers, int firstOctave, AngleMode angleMode, //common parameters double threshold, double edgeThreshold, //detector parameters double magnification, [MarshalAs(CvInvoke.BoolMarshalType)] bool isNormalize, [MarshalAs(CvInvoke.BoolMarshalType)] bool recalculateAngles);
/// <summary> /// Rotates the Transform to another euler orientation over time. /// </summary> static public Tween RotateTo(this Transform inTransform, Vector3 inTarget, float inTime, Axis inAxis = Axis.XYZ, Space inSpace = Space.World, AngleMode inMode = AngleMode.Shortest) { return(Tween.Create(new TweenData_Transform_EulerRotationFixed(inTransform, inTarget, inSpace, inAxis, inMode), inTime)); }
/// <summary> /// Rotates the Transform to another euler orientation over time. /// </summary> static public Tween RotateTo(this Transform inTransform, float inTarget, TweenSettings inSettings, Axis inAxis, Space inSpace = Space.World, AngleMode inMode = AngleMode.Shortest) { return(Tween.Create(new TweenData_Transform_EulerRotationFixed(inTransform, new Vector3(inTarget, inTarget, inTarget), inSpace, inAxis, inMode), inSettings)); }
/// <summary>Converts a world position to an angle around the origin.</summary> /// <returns>Angle between the point and the grid's "right" axis.</returns> /// <param name="worldPoint">Point in world space.</param> /// <param name="mode">The mode of the angle, defaults to radians.</param> /// /// This method returns which angle around the grid a given point in world space has. public float World2Angle(Vector3 worldPoint, AngleMode mode = AngleMode.radians) { return WorldToPolar(worldPoint)[idx[1]] * (mode == AngleMode.radians ? 1.0f : Mathf.Rad2Deg); }