# 配置する

• だいたいN個の点を半径１の球面上に「ほぼ均一に配置する」
• N=1000を指定して1513個の点がプロットされた・・・(これが誤差)
• Javaで３次元座標として出力する
```public static void main(String[] args)throws IOException {
int N=1000;
new SphereCoords sc = new SphereCoords(N);
SphereCoords scds = new SphereCoords(numnode);

String outfile="out.txt";
scds.Print2FileXYZ(outfile, "\t", "\n", "");
}```
```package sPherePlot;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

public class SphereCoords {
int N;
double theta;
//double[] latitude;//緯度
//double[] longitude;//経度

double[][] cdsLatitude;
double[][] cdsLongitude;
public SphereCoords(int N_){
N=N_;
theta=4/Math.sqrt((double)N);
int n=(int)(2*Math.PI/theta);
int neq=n/2;
//longitude =new double[n];
cdsLatitude=new double[n][0];
cdsLatitude[neq]=new double[n];
cdsLongitude=new double[n][0];
cdsLongitude[neq]=new double[n];
for(int i=0;i<cdsLatitude[neq].length;i++){
cdsLatitude[neq][i]=0;
cdsLongitude[neq][i]=i*theta;
}
for(int i=neq+1;i<cdsLatitude.length;i++){
int n2=(int)(2*Math.PI*Math.abs(Math.cos(theta*(i-neq)))/theta);
//System.out.println("n="+n+" i "+i+" n2 "+n2);
if(i<cdsLatitude.length){
cdsLatitude[i]=new double[n2];
cdsLongitude[i]=new double[n2];
}
if(neq-(i-neq)>=0){
cdsLatitude[neq-(i-neq)]=new double[n2];
cdsLongitude[neq-(i-neq)]=new double[n2];
}

for(int j=0;j<cdsLatitude[i].length;j++){
if(i<cdsLatitude.length){
cdsLatitude[i][j]=cdsLongitude[neq][i-neq];
//cdsLongitude[i][j]=j*theta/Math.cos(cdsLatitude[i][j]);
cdsLongitude[i][j]=j*2*Math.PI/(double)n2;
}
if(neq-(i-neq)>=0){
cdsLatitude[neq-(i-neq)][j]=-cdsLongitude[neq][neq-(i-neq)];
//cdsLongitude[neq-(i-neq)][j]=j*theta/Math.cos(cdsLatitude[neq-(i-neq)][j]);
cdsLongitude[neq-(i-neq)][j]=j*2*Math.PI/(double)n2;
}

}
}

}

public static double[] r2xyz(double r1,double r2){
double[] ret=new double[3];
ret[0]=Math.cos(r1)*Math.cos(r2);
ret[1]=Math.cos(r1)*Math.sin(r2);
ret[2]=Math.sin(r1);
return ret;
}

public void PrintR(String sep1,String sep2,String sep3){
for(int i=0;i<cdsLatitude.length;i++){
for(int j=0;j<cdsLatitude[i].length;j++){
System.out.print(cdsLatitude[i][j]+sep1+cdsLongitude[i][j]+sep2);
}
System.out.print(sep3);
}
}
public void PrintXYZ(String sep1,String sep2,String sep3){
for(int i=0;i<cdsLatitude.length;i++){
for(int j=0;j<cdsLatitude[i].length;j++){
double[] xyz=r2xyz(cdsLatitude[i][j],cdsLongitude[i][j]);
for(int k=0;k<xyz.length;k++){
System.out.print(xyz[k]+sep1);
}
System.out.print(sep2);
}
System.out.print(sep3);
}
}
public void Print2FileXYZ(String file,String sep1,String sep2,String sep3)throws IOException{
BufferedWriter[] bw = new BufferedWriter[1];
bw[0] = new BufferedWriter(new FileWriter(file));
try{
//bw1 = new BufferedWriter(new FileWriter(file));
for(int i=0;i<cdsLatitude.length;i++){
for(int j=0;j<cdsLatitude[i].length;j++){
double[] xyz=r2xyz(cdsLatitude[i][j],cdsLongitude[i][j]);
String st="";

for(int k=0;k<xyz.length;k++){
st+=xyz[k]+sep1;
//System.out.print(xyz[k]+sep1);
}
st+=sep2;
bw[0].write(st);

}
bw[0].write(sep3);
}

bw[0].close();

}catch(Exception e){

System.out.println(e);

}
}

}```
• 出てきたファイルをRでプロット
```> library(scatterplot3d)