plunkerでopenjscad その9

# 概要
plunkerでopenjscadやってみる。
polyhedron使ってみた。


# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/1a95f2ca-33ba-1570-cb3f-cbdc2608612f.png)


# サンプルコード

```

function graphFunction(x, y) {
	return (x / (y));
}
function findPoint(x, y) {
	return parseInt(parseInt((x - xMin) / xStep) * yLen + parseInt((y - yMin) / yStep));
}
var xMin = 1;
var yMin = 1;
var xMax = 9;
var yMax = 9;
var xStep = 0.125;
var yStep = 0.125;
var xLen = ((xMax - xMin) / xStep) + 1;
var yLen = ((yMax - yMin) / yStep) + 1;
function main() {
	var points = []; 
	var faces = [];
	xMax += xStep;
	yMax += yStep;
	var zMin = 0;
	for(x = xMin; x < xMax; x += xStep)
	{
		for(y = yMin; y < yMax; y += yStep)
		{
			points.push([x, y, graphFunction(x, y)]);
			if (graphFunction(x, y) < zMin)
			{
				zMin = graphFunction(x, y);
			}
		}
	}
	for(x = xMin; x < xMax; x += xStep)
	{
		points.push([x, yMin, zMin]);
	}
	for(y = yMin; y < yMax; y += yStep)
	{
		points.push([xMin, y, zMin]);
	}
	for(x = xMin; x < xMax; x += xStep)
	{
		points.push([x, yMax - yStep, zMin]);
	}
	for(y = yMin; y < yMax; y += yStep)
	{
		points.push([xMax - xStep, y, zMin]);
	}
	for(x = xMin; x < xMax - xStep; x += xStep)
	{
		for(y = yMin; y < yMax - yStep; y += yStep)
		{
			faces.push([parseInt(findPoint(x + xStep, y)), parseInt(findPoint(x, y)), parseInt(findPoint(x + xStep, y + yStep))]);
			faces.push([parseInt(findPoint(x, y)), parseInt(findPoint(x, y + yStep)), parseInt(findPoint(x + xStep, y + yStep))]);
		}
	}
	var pos = 0;
	var numPoints = points.length;
	for(x = xMin; x < xMax - xStep; x += xStep)
	{
		pos = parseInt((x - xMin) / xStep);
		faces.push([parseInt(pos+(numPoints - 2 * xLen - 2 * yLen)), parseInt(findPoint(x, yMin)), parseInt(findPoint(x + xStep, yMin))]);
		faces.push([parseInt(pos+(numPoints - 2 * xLen - 2 * yLen) + 1), parseInt(pos + (numPoints - 2 * xLen - 2 * yLen)), parseInt(findPoint(x + xStep, yMin))]);
	}
	for(x = xMin; x < xMax - xStep; x += xStep)
	{
		pos = parseInt((x - xMin) / xStep);
		faces.push([parseInt(findPoint(x, yMax - yStep)), parseInt(pos + (numPoints - xLen - yLen)), parseInt(findPoint(x + xStep, yMax - yStep))]);
		faces.push([parseInt(pos + (numPoints - xLen - yLen)), parseInt(pos + (numPoints - xLen - yLen) + 1), parseInt(findPoint(x + xStep, yMax - yStep))]);
	}
	for(y = yMin; y < yMax - yStep; y += yStep)
	{
		pos = parseInt((y - yMin) / yStep);
		faces.push([parseInt(findPoint(xMin, y)), parseInt(pos + (numPoints - xLen - 2 * yLen)), parseInt(findPoint(xMin, y + yStep))]);
		faces.push([parseInt(pos + (numPoints - xLen - 2 * yLen)), parseInt(pos + (numPoints - xLen - 2 * yLen) + 1), parseInt(findPoint(xMin, y + yStep))]);
	}
	for(y = yMin; y < yMax - yStep; y += yStep)
	{
		pos = parseInt((y - yMin) / yStep);
		faces.push([parseInt(pos + (numPoints - yLen)), parseInt(findPoint(xMax - xStep, y)), parseInt(findPoint(xMax - xStep, y + yStep))]);
		faces.push([parseInt(pos + (numPoints - yLen) + 1), parseInt(pos + (numPoints - yLen)), parseInt(findPoint(xMax - xStep, y + yStep))]);
	}
	faces.push([numPoints - 2 * xLen - 2 * yLen, numPoints - xLen - 2 * yLen - 1, numPoints - 1]);
	faces.push([numPoints - xLen - yLen, numPoints - 2 * xLen - 2 * yLen, numPoints - 1]);
	return CSG.polyhedron({
		points: points,
		faces: faces
	});
}
```


# 成果物

https://embed.plnkr.co/plunk/9ctrY0xtBSP6KMPt


以上。