====== Using Rhino to Solve Mathematical Equations ====== Rhino is a 3-D modeling application that can solve graphically. For example, if you want to know if two curves or surfaces intersect, you can use the **Intersect** command. If you want to know the centroid, volume or principal moments, you can ask Rhino that, too. You can also use Rhino to solve mathematical equations. But Rhino does not have commands like //solve equation// or //plot graph//. The standard keyboard is also a problem. Where is the square root sign, superscript, or subscript? So, you will need to use scripting. Rhino has a script editor made specifically to help with these problems. **Rhino 5 contains two scripting languages:** * **[[http://wiki.mcneel.com/developer/python|RhinoPython]]** * **[[http://wiki.mcneel.com/developer/rhinoscript|RhinoScript]]** Rhino 4 contains only **RhinoScript**. //Because of this, we recommend using RhinoScript.// [[http://discourse.mcneel.com/|{{:developer:mcdiscourse.png |http://discourse.mcneel.com/}}]] Ask questions on our [[http://discourse.mcneel.com|discourse support forum]]. When posting questions, please use either the **[[http://discourse.mcneel.com/category/rhino-developer|Rhino Developer]]** or the **[[http://discourse.mcneel.com/category/scripting|Scripting]]** category. ===== The basics ===== To illustrate how you can use **RhinoScript** to solve mathematical problems, I have written two simple scripts that solve the first two questions of the math practice test. Note, both of these solutions can be copied and pasted into the RhinoScript editor (//EditScript//) for testing. You also need to know the commands //LoadScript// and //RunScript//. The basic steps are: - Write a script function in script editor **EditScript**. - Or load a an existing file with the .rvb extension into the script editor. - Run the **LoadScript** command to load a script into memory. - Use the **RunScript** command to run the function name. Note: Dragging a .rvb file onto the Rhino window will load and run the script. * From the Rhino Help menu, click Plug-ins and then click **RhinoScript**. Also see [[http://wiki.mcneel.com/developer/vbsfundamentals|VB Fundamentals.]] ===== Examples ===== ==== 1. Graph the following equation: y = (x - 4)^2 = 2 ==== ' Define range of x values xrange = Array(-4, -2, 0, 2, 4, 6, 8, 10) ' With each x value For Each x In xrange ' Solve for y y = (x-4)^2 + 2 ' Add a point at the x,y location Rhino.AddPoint Array(x, y) Next ===== 2. Equation f(x) = x^2 - 5x - 14 ===== Find zeros of function using these values: 2, 7, -2, -7, then print to Rhino command prompt. ' Define range of x values xrange = Array(2, 7, -2, -7) ' With each x value For Each x In xrange ' Solve for y, where y = f(x) y = (x^2) - (5*x) - 14 ' If y is zero, print x If y = 0 Then Rhino.Print x Next ===== 3. RhinoScript Quadratic Solver ===== See [[http://wiki.mcneel.com/developer/scriptsamples/quadraticsolver|A Quadratic Solver in Script.]] ===== 4. Finding the Perfect Squares ===== See [[http://wiki.mcneel.com/developer/scriptsamples/perfectsquare|Finding Perfect Squares.]] //The great thing about scripting is that it can be adapted to solve nearly any problem and in any manner chosen by the script writer.//