![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
今回の記事の目的はProcessingの「dist()
関数」を理解し、自分なりに使ってみること。
この記事を書いた人
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-user-profile-illustrationi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-user-profile-illustrationi-light-blue.png)
- クリエイティブコーディングで制作した作品と、上達のためにやったこと・学習過程を発信
- コンセプトは「クリエイティブコーディング1万時間の歩き方」
- 2024年にProcessingの構文のアウトプットを終え、2025年から作品制作開始(クリエイティブコーディングで作成した作品集)
目次
【Processing】dist()関数について
dist()関数について
- distは英語のdistance(距離)の略
dist()
は2つの点の間の直線距離を求めるための関数- 点 (x1, y1) と点 (x2, y2) の距離を計算するのに使う
【Processing】dist()関数の書き方【構文】
dist()関数の書き方【構文】
dist(x1, y1, x2, y2)
- 2つの点 (x1, y1) と (x2, y2) の間の距離を計算
dist(x1, y1, z1, x2, y2, z2)
- 3次元空間における2つの点 (x1, y1, z1) と (x2, y2, z2) の間の距離を計算
【Processing】dist()関数の使い方2つ【画像とコード】
【1】dist(x1, y1, x2, y2)の例
![【1】dist(x1, y1, x2, y2)の例](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/using-dist-to-find-distance1.png)
![【1】dist(x1, y1, x2, y2)の例](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/using-dist-to-find-distance1.png)
size(400, 400); // ウィンドウのサイズを設定
// A点の座標
float x1 = 100;
float y1 = 0;
// B点の座標
float x2 = 300;
float y2 = 0;
// 2つの点の間の距離を計算
float distance = dist(x1, y1, x2, y2);
// 計算した距離を表示
println("2つの点の距離は: " + distance);
【2】dist(x1, y1, z1, x2, y2, z2)の例
![【2】dist(x1, y1, z1, x2, y2, z2)の例](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/using-dist-to-find-distance2.png)
![【2】dist(x1, y1, z1, x2, y2, z2)の例](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/10/using-dist-to-find-distance2.png)
void setup() {
size(400, 400); // 画面の大きさを設定
// A点の座標
float x1 = 10;
float y1 = 20;
float z1 = 30;
// B点の座標
float x2 = 40;
float y2 = 50;
float z2 = 60;
// 2つの点の間の距離を計算
float distance = dist(x1, y1, z1, x2, y2, z2);
// 計算した距離を表示
println("A点とB点の間の距離は: " + distance);
}
【Processing】dist()関数はどんな表現で使えそうか
A地点とB地点にある図形の距離の間に、新しい表現を描きたいなという場合に使ってみたいと思います。
【Processing】dist()関数を使ってみた感想
あえて2点間の距離を数値で見えるように表現するのも面白そう。
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
![](https://watataku-artist-katsuyaku.com/wp-content/uploads/2024/03/watataku-hukidashi-light-blue.png)
それでは今日もレッツワクワクコーディング。