-1

你能告诉我怎么画一个strophoid吗?
我写了这个循环来构建它

for (int i = 0; i < 360; i += 5) {
                double u=Math.tan(i);
                x[i] = (int) (a * (Math.pow(u,2)-1)/(Math.pow(u,2)+1));
                y[i] = (int) (a * u* (Math.pow(u,2)-1)/(Math.pow(u,2)+1));
                gfx.drawLine(x[i], y[i], x[i], y[i]);
            }

但我得到了这样的图形

4

2 回答 2

1

我认为你的问题在于这条线:你在线的两端gfx.drawLine(x[i], y[i], x[i], y[i]);
使用相同的索引,所以你实际上画了一个点。i

于 2013-03-21T19:09:05.327 回答
1

好吧..我找到了使用 JFreeChart 的解决方案

import javax.swing.JFrame;


import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataItem;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;



public class Strofoida extends JFrame {


public Strofoida() {
    super();
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    XYSeries series = createSeries();
    XYDataset xyDataset = new XYSeriesCollection(series);
    JFreeChart localJFreeChart = ChartFactory.createXYLineChart("", "X", "Y", xyDataset, PlotOrientation.VERTICAL,
            true, true, false);
    XYPlot localXYPlot = (XYPlot) localJFreeChart.getPlot();
    localXYPlot.setDomainZeroBaselineVisible(true);
    localXYPlot.setRangeZeroBaselineVisible(true);
    ChartPanel chartPanel = new ChartPanel(localJFreeChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
    setContentPane(chartPanel);
}

private XYSeries createSeries() {
    XYSeries ser = new XYSeries(new XYDataItem(0, 0), false);
    int a = 1;
    for (double f = -0.9; f <= 0.9; f += 0.01) {
        double u = Math.tan(f);
        ser.add(a * (u * u - 1) / (u * u + 1), a * u * (u * u - 1) / (u * u + 1));
    }
    return ser;
}

static class Main {
    public static void main(String[] args) {
        Strofoida strofoida = new Strofoida();
        strofoida.pack();
        strofoida.setVisible(true);
    }
}


}
于 2013-03-25T12:33:05.867 回答