<?php 
// print http-header for svg-dokument
header("Content-Type: image/svg+xml");
header("Content-Disposition: inline; filename=coilgraph.svg");
header("Content-Location: coilgraph.svg");
echo 
"<?";
?>xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="800px" height="800px" viewBox="0 0 1000 1000">
  <defs>
    <marker id="pfeilspitze"
      viewBox="0 0 40 16" refX="0" refY="8" 
      markerUnits="strokeWidth"
      markerWidth="10" markerHeight="4"
      orient="auto">
      <path d="M0,0 L40,8 L0,16 z"/>
    </marker>
  </defs>

  <g id="graph">
    <path style="stroke:#000000;stroke-width:4;fill:none" d="M100 900 v-840" marker-end="url(#pfeilspitze)"/>
    <path style="stroke:#000000;stroke-width:4;fill:none" d="M100 900 h840" marker-end="url(#pfeilspitze)"/>

    <text x="50" y="100" writing-mode="tb-rl" font-weight="bold" font-size="30" font-family="Arial">
    Y-Achse
    </text>
    <text x="900" y="960" font-weight="bold" font-size="30" font-family="Arial" text-anchor="end">
    X-Achse
    </text>
  </g>

  <g>
    <path id="spirale" style="stroke:#000000;stroke-width:4;fill:none" d="<?php

##
## Print the coils as 2D
##

$R=50;        // radius 
$H=-5;        // z-axis growing-factor of coil
$U=12;        // turns
$Q=5;    // x-axis moving factor per radiant
$A=0;        // projection-
$B=1;        // layer..
$C=0;        // ..for coil-
$D=$R+1;    // "shadow"

$V["l"]=0;    // position-
$V["m"]=1;    // vector (0,1,0) || y-axis
$V["n"]=0.3;    // a little higher view position

$S["x"]=(float)160;    // coil
$S["y"]=(float)-51;    // start 
$S["z"]=(float)800;    // point

$t=0;        // radiant running start
$p=0;        // intermediate result
$r["x"]=0;     // x 
$r["y"]=0;     // y 
$r["z"]=0;     // z 

$oo=false;

for (
$t$t<=(float)($U*2*pi()); $t+=0.1) {

 
// calculate coil
 
$r["x"]=$S["x"] + (float)($R*cos($t))+(float)($t*$Q);
 
$r["y"]=$S["y"] + $R*sin($t);
 
$r["z"]=$S["z"] + $H*$t;

 
// projection on layer
 
$p=(float)(($A*$r["x"])+($B*$r["y"])+($C*$r["z"])+$D) / (float)(($A*$V["l"])+($B*$V["m"])+($C*$V["n"]));

 
$tx=(float)($r["x"]-(float)($V["l"]*$p));
 
// $ty=(float)($r["y"]-(float)($V["m"]*$p));
 
$tz=(float)($r["z"]-(float)($V["n"]*$p));

 if (!
$oo$oo="M";
 elseif (
$oo=="M"$oo="L";

 echo 
$oo.$tx;
 echo 
",".$tz." ";

 }

?>" marker-end="url(#pfeilspitze)"/>

 </g>

</svg>