Find the parameters (a0,a1,a2,a3) for the Cubic Hermite curve that connect p0=(30,50) with p1=(30,10), where 0 =
Question:
Find the parameters (a0,a1,a2,a3) for the Cubic Hermite curve that connect p0=(30,50) with p1=(30,10), where 0 = (40,0) 1 = (40,0)
b) Modify the code in the java file 'part2.java' (see Lab->Lab1 on BB) to draw the Cubic Hermite curve you solved in Q2(a). Hint: you need the use the parametric equation generated in Q2(a)
import java.awt.Color; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.HeadlessException; import java.awt.geom.Line2D; import java.util.ArrayList; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException;
public class Part2 extends JFrame {
public static void main(String[] args) { new Part2(); }
public Part2() throws HeadlessException { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); }
JFrame frame = new JFrame("Draw my cicle"); frame.add(new TestPane()); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } // create figure
public class TestPane extends JPanel {
ArrayList lines = new ArrayList<>();
public TestPane() { drawCircle(150, 350.0, 350.0); }
@Override public Dimension getPreferredSize() { return new Dimension(600, 600); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create();
g2d.setColor(Color.RED); System.out.println(lines.size()); for (Line2D s : lines) { g2d.draw(s); } g2d.dispose(); }
public void drawCircle(int radio, double xCenter, double yCenter) { double t = 0; double xPoint; double yPoint; double xActual = xCenter + radio; double yActual = yCenter; double step = .1; while (t <= 360) { xPoint = xCenter + radio * Math.cos((t/180)*Math.PI); yPoint = yCenter - radio * Math.sin((t/180)*Math.PI);
// System.out.println(xActual + "x" + yActual + "x" + xPoint + "x" + yPoint); lines.add(new Line2D.Double(xActual, yActual, xPoint, yPoint));
t += step; xActual = xPoint; yActual = yPoint; } } } //plot the 2d lines
}
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill