⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 polar.java

📁 JAVA 数学程序库 提供常规的数值计算程序包
💻 JAVA
字号:
package jmathlib.toolbox.jmathlib.graphics.graph2d;

import jmathlib.core.tokens.*;
import jmathlib.core.functions.ExternalFunction;
import jmathlib.core.tokens.numbertokens.DoubleNumberToken;
import jmathlib.core.interpreter.ErrorLogger;

/**An external function for 2 dimensional plots*/
public class polar extends ExternalFunction
{

    public OperandToken evaluate(Token[] operands)
    {

        ErrorLogger.debugLine("polar evaluate");

        if (getNArgIn(operands) == 0)
            throwMathLibException("polar: number of arguments > 0");
            
        if (!(operands[0] instanceof DoubleNumberToken)) 
            throwMathLibException("polar: first argument must be a number");

        double[][] x = ((DoubleNumberToken)operands[0]).getReValues();
        int   xSizeX = ((DoubleNumberToken)operands[0]).getSizeX();
        int   xSizeY = ((DoubleNumberToken)operands[0]).getSizeY();

        double[][] y;
        int ySizeX;
        int ySizeY;


        //    color            linestyle   marker               
        //  y   yellow     -     solid    .     point             
        //  m   magenta    :     dotted   o     circle             
        //  c   cyan       -.    dashdot  x     x-mark              
        //  r   red        --    dashed   +     plus                
        //  g   green                     *     star
        //  b   blue                      s     square
        //  w   white                     d     diamond
        //  k   black                     v     triangle (down)
        //                                ^     triangle (up)
        //                                <     triangle (left)
        //                                >     triangle (right)
        //                                p     pentagram
        //                                h     hexagram

        char colorC     ='r';
        char markerC   = ' ';
        char lineStyleC =' ';

        if (operands.length >= 2)
        {
            if (!(operands[1] instanceof DoubleNumberToken)) return null;

            y       = ((DoubleNumberToken)operands[1]).getReValues(); 
            ySizeX  = ((DoubleNumberToken)operands[1]).getSizeX();  
            ySizeY  = ((DoubleNumberToken)operands[1]).getSizeY();

            //ErrorLogger.debugLine("plot frame "+xSizeX);
            if ((xSizeX != ySizeX) || (xSizeY!=1)) return null;


            // Look for style information
            if (operands.length==3)
            {
                if (operands[2] instanceof CharToken)
                {
                    String s = ((CharToken)operands[2]).getValue();
                    boolean dashSwitch = false;
                    for (int n=0; n<s.length(); n++)
                    {
                        char c = s.charAt(n);
                        switch (c)
                        {
                            case 'y':
                            case 'm':
                            case 'c':
                            case 'r':
                            case 'g':
                            case 'b':
                            case 'w':
                            case 'k': colorC = c;
                                      break;
                            case '-': lineStyleC = c;
                                      if (dashSwitch)
                                      {
                                          // -- (dashed)
                                          lineStyleC = 'd';
                                          break;
                                      }
                                      dashSwitch = true;
                                      break;
                            case ':': lineStyleC = c;
                                      break;
                            case '.':
                                      if (dashSwitch)
                                      {
                                          // -. (dash-dotted)
                                          lineStyleC = '.';
                                          break;
                                      }
                            case 'o':
                            case 'x':
                            case '+':
                            case '*':
                            case 's':
                            case 'd':
                            case 'v':
                            case '^':
                            case '<':
                            case '>':
                            case 'p':
                            case 'h': markerC = c;
                                      break;
                            default:
                        }
                    }
                }
            }

            ErrorLogger.debugLine("polar: types: "+colorC+" "+markerC+" "+lineStyleC);

            getGraphicsManager().getCurrentFigure().getCurrentPolarAxes().addLines(x[0],y,
                                                                              new Character(colorC).toString(),
                                                                              new Character(markerC).toString(),
                                                                              new Character(lineStyleC).toString());
            getGraphicsManager().getCurrentFigure().repaint();
        }
        else
        {
            // plot was called with only one argument e.g.: plot(matrix)
            double[][] xx = new double[1][x[0].length];
            for(int i=0; i<x[0].length; i++) xx[0][i]=(double)(i+1);

            // changed order
            getGraphicsManager().getCurrentFigure().getCurrentPolarAxes().addLines(xx[0],x,
                                                                             new Character(colorC).toString(),
                                                                             new Character(markerC).toString(),
                                                                             new Character(lineStyleC).toString());
            getGraphicsManager().getCurrentFigure().repaint();
        }


        return null;
    }
}

/*
@GROUP
graphics
@SYNTAX
polar(x-values, y-values, graph settings)
@DOC
Plots a graph of the supplied points in polar coordinates
@EXAMPLES
<programlisting>
polar([1,2,3], RAND(3), 'b')
</programlisting>
@NOTES
<programlisting>
graph settings
color
y   yellow
m   magenta
c   cyan
r   red
g   green
b   blue
w   white
k   black

linestyle
-     solid
:     dotted
-.    dashdot
--    dashed

marker
.     point
o     circle
x     x-mark
+     plus
*     star
s     square
d     diamond
v     triangle (down)
^     triangle (up)
&lt;     triangle (left)
&gt;     triangle (right)
p     pentagram
h     hexagram
</programlisting>
@SEE
plot
*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -