Inductor drawn symmetrically.
Command window output:
C:\ece538\circuit3>java MyGroup5 inductor at (0,0) BoundsInLocal: xcen 0.00000 ycen 0.00000 width 7.20833 height 4.20833 BoundsInParent: xcen 0.00000 ycen 0.00000 width 0.720833 height 0.420833 inductor at (1,1) BoundsInLocal: xcen 0.00000 ycen 0.00000 width 7.20833 height 4.20833 BoundsInParent: xcen 1.00000 ycen -1.00000 width 0.720833 height 0.420833
MyGroup5.javaimport javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.collections.*;
import javafx.geometry.Bounds;
import java.lang.Math;
public class MyGroup5 extends Application {
public void start(Stage stage) {
Group grp = new Group();
Scene scene = new Scene(grp, 400, 400);
grp.setTranslateX(scene.getWidth()/2);
grp.setTranslateY(scene.getHeight()/2);
double res = 96;
grp.setScaleX(res);
grp.setScaleY(res);
//grp.setRotate(10.0);
Grid.draw(grp);
drawImpedance(grp);
System.out.println("\ninductor at (0,0)");
drawInductor(grp,0.0,0.0);
System.out.println("\ninductor at (1,1)");
drawInductor(grp,1.0,1.0);
stage.setTitle("MyGroup5 Test");
stage.setScene(scene);
stage.show();
}
void drawImpedance(Group parent)
{
Group grp = new Group();
double resc = 0.1;
grp.setScaleX(resc);
grp.setScaleY(resc);
double res = parent.getScaleX();
Path mypath = new Path();
ObservableList<PathElement> p = mypath.getElements();
p.add(new MoveTo(-2.5,0));
p.add(new LineTo(-2.0,0));
p.add(new MoveTo(2.0,0));
p.add(new LineTo(2.5,0));
mypath.setStrokeWidth(20/res);
//mypath.setStroke(Color.GREEN);
mypath.setStrokeLineCap(StrokeLineCap.ROUND);
ObservableList<Node> ol = grp.getChildren();
ol.add(mypath);
Rectangle r = new Rectangle(-2.0,-1.25,4.0,2.5);
r.setFill(null);
r.setStroke(Color.GREEN);
r.setStrokeWidth(20/res);
ol.add(r);
parent.getChildren().add(grp);
double xpos = -1.0, ypos = 0.0;
grp.setTranslateX(xpos);
grp.setTranslateY(-ypos);
}
void show_bounds(Group grp) {
double xcen, ycen;
Bounds b1 = grp.getBoundsInLocal();
//System.out.println("BoundsInLocal: " + b1);
xcen = 0.5*(b1.getMinX()+b1.getMaxX());
ycen = 0.5*(b1.getMinY()+b1.getMaxY());
System.out.format("\nBoundsInLocal: xcen %g ycen %g width %g height %g\n",
xcen, ycen, b1.getWidth(), b1.getHeight());
Bounds b2 = grp.getBoundsInParent();
xcen = 0.5*(b2.getMinX()+b2.getMaxX());
ycen = 0.5*(b2.getMinY()+b2.getMaxY());
//System.out.println("BoundsInParent: " + b2);
System.out.format("BoundsInParent: xcen %g ycen %g width %g height %g\n",
xcen, ycen, b2.getWidth(), b2.getHeight());
}
void drawInductor(Group parent,double xpos, double ypos)
{
double[] xpts = {-2.75,-2.75,-1.25,-1.25,-1.25,-1.75,-1.75};
double[] ypts = { 0.0,-2.0,-2.0, 0.0, 2.0, 2.0, 0.0};
Group grp = new Group();
double resc = 0.1;
grp.setScaleX(resc);
grp.setScaleY(resc);
double res = parent.getScaleX();
Path mypath = new Path();
ObservableList<PathElement> p = mypath.getElements();
p.add(new MoveTo(-3,0));
p.add(new LineTo(-2.75,0));
p.add(new CubicCurveTo(xpts[1],ypts[1],xpts[2],ypts[2],xpts[3],ypts[3]));
p.add(new CubicCurveTo(xpts[4],ypts[4],xpts[5],ypts[5],xpts[6],ypts[6]));
for (int n=0; n<4; n++) {
for (int j=0; j<7; j++) xpts[j] += 1.0;
p.add(new CubicCurveTo(xpts[1],ypts[1],xpts[2],ypts[2],xpts[3],ypts[3]));
if (n<3) p.add(new CubicCurveTo(xpts[4],ypts[4],xpts[5],ypts[5],xpts[6],ypts[6]));
}
p.add(new LineTo(3,0));
mypath.setFill(null);
mypath.setStrokeWidth(20/res);
mypath.setStroke(Color.GREEN);
mypath.setStrokeLineCap(StrokeLineCap.ROUND);
ObservableList<Node> ol = grp.getChildren();
ol.add(mypath);
parent.getChildren().add(grp);
grp.setTranslateX(xpos);
grp.setTranslateY(-ypos);
show_bounds(grp);
}
}
Maintained by John Loomis, updated Thu Feb 08 16:18:30 2018