-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurfacePlot.pl
More file actions
34 lines (30 loc) · 1.04 KB
/
surfacePlot.pl
File metadata and controls
34 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/env perl
use lib "../lib";
use CAD::OpenSCAD;
surfacePlot(-30,-30,30,30,3,1,"saddle");
sub function{
my ($x,$y,$fn)=@_;
for ($fn){
$_ eq "saddle" && do { return ($y**2)/40-($x**2)/40;};
$_ eq "waves" && do { return 5*sin(sqrt($y**2+$x**2)/5);};
$_ eq "conic" && do { return (sqrt($y**2+$x**2));};
$_ eq "parabolic" && do { return ($y**2+$x**2)/40; };
$_ eq "cubic" && do { return ($y**3+$x**3 )/1000; };
}
}
sub surfacePlot{
my ($minX,$minY,$maxX,$maxY,$spacing,$pixel,$funct)=@_;
my $chart=new OpenSCAD;
my ($col,$row)=(0,0);
for(my $x=$minX;$x<$maxX;$x+=$spacing){
for(my $y=$minY;$y<$maxY;$y+=$spacing){
$chart->cube("C_".$col."_".$row,$pixel)->translate("C_".$col."_".$row,[$x,$y,function($x,$y,$funct)]);
if ($row){ $chart->hull("H_".$col."_".$row."_X","C_".$col."_".$row,"C_".$col."_".($row-1))};
if ($col){ $chart->hull("H_".$col."_".$row."_Y","C_".$col."_".$row,"C_".($col-1)."_".$row)};
$row++;
}
$col++;
$row=0;
}
$chart->cleanUp(qr{^C_})->build(keys %{$chart->items})->save("hull");
}