Download java source from src.zip
The idea is to create a grid (1 unit per division) instead of using pixel coordinates.
The Swing version is shown in Testbed1.java
see MyGroup1.java
The plan now is to use JavaFX Group objects. The plan is to use Shape objects, such as Line and Path instead of graphics generated by a GraphicsContext object.
We use transformations to convert from pixel coordinates to grid coordinates.
All transformations are located in the javafx.scene.transform
package and are subclasses of the
Transform class.
The relevant code is as follows:
Group grp = new Group(); Scene scene = new Scene(grp, 400, 400); Translate tr = new Translate(scene.getWidth()/2,scene.getHeight()/2); int res = 48; //98; Scale scl = new Scale(res,res); grp.getTransforms().addAll(tr,scl);
see MyGroup2.java
Here we use the internal transformation properties defined in Node, which is in the parent tree for Group. These seem more appropriate for GUI uses.
The relevant code follows:
Group grp = new Group(); Scene scene = new Scene(grp, 400, 400); grp.setTranslateX(scene.getWidth()/2); grp.setTranslateY(scene.getHeight()/2); double res = 48; //98; grp.setScaleX(res); grp.setScaleY(res); grp.setRotate(10.0);
see Capacitor1.java
This first version is a standalone program that draws a capacitor, using a Path object. It derives from an earlier AWT/Swing version capacitor.java
see Capacitor2.java
and MyCap.java
The second version uses a separate capacitor class which constructs a Group and adds it to the parent group.
see MyGroup3.java
Here we superimpose two instances of Capacitor2
over the parent grid.
see MyGroup4.java
Here we replace the Line objects in the grid with a couple of Path objects.
See Grid.java
Separate the grid draw function to another class.
See Group4t.java
Try to draw an inductor. Unfortunately, the drawing is not centered correctly.
See GroupTest.java
Test hypothesis that group objects must be symmetric about the origin.
See MyGroup5.java
Rewrite the inductor drawing so that it is symmetric about the origin.
Maintained by John Loomis, last updated 18 April 2017