Difference between revisions of "Category:LSL Vector/ja"

From Second Life Wiki
Jump to navigation Jump to search
m (categorized category)
m
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{LSL Header/ja|ml=*}}{{LSLC/ja|}}{{LSLC/ja|Types}}
{{Multi-lang}}
{{LSL Header/ja|ml=*}}
{{LSLC/ja|}}{{LSLC/ja|Types}}
==Vector==
==Vector==
vectorは3個の{[[float/ja|float]]の値のセットを含むデータ[[:Category:LSL Types/ja|型(type)]]です。


vectorは3個の[[LSL_float/ja|float]]の値のセットを含むデータ[[:Category:LSL Types/ja|型(type)]]です。各要素は変数名の後に .x、.y、.zを付加することにより個別にアクセスできます。 
===成分===
各要素は変数名の後に .x、.y、.zを付加することにより個別にアクセスできます。
<syntaxhighlight lang="lsl2">
vector vec = <1, 2, 3>;
float x = vec.x; // 1.0
float y = vec.y; // 2.0
float z = vec.z; // 3.0
</syntaxhighlight>


===用途===
vector型は次のデータを保持するために使うことができます:
vector型は次のデータを保持するために使うことができます:
* 位置: x, y, zの単位はm(メートル)
* {{LSLGC|Movement/ja|位置}}: x, y, zの単位はm(メートル)
* 速度: x, y, zはスピードをあらわします。
* {{LSLGC|Movement/ja|速度}}: x, y, zはスピードをあらわします。 1秒あたりのm(メートル)
* {{LSLGC|Color|色}}: Redはx、Greenはy、Blueはz
* {{LSLGC|Color|色}}: Redはx、Greenはy、Blueはz


===演算子===
vector型は次の操作をサポートしています:
vector型は次の操作をサポートしています:
* 加算、"+" 演算子
==== 加算、"+" 演算子 ====
* 減算、"-" 演算子
<syntaxhighlight lang="lsl2">
* 乗算 (内積)、 "*" 演算子
vector v = <1, 2, 3> + <0.5, 0.0, 3>; // <1.5, 2.0, 6.0>
* 外積、"%" 演算子
</syntaxhighlight>


vector型は[[Quaternion]]の乗算または除算によって回転させることができます。
==== 減算、"-" 演算子 ====
<syntaxhighlight lang="lsl2">
vector v = <1, 1, 1> - <0.5, 0.0, 3>; // <0.5, 1.0, -2.0>
</syntaxhighlight>


======
==== 乗算 (内積)、 "*" 演算子 ====
<pre>
<syntaxhighlight lang="lsl2">
vector test=<1.0, 2.0, 3.0>;
float f = <9, 2, 7> * <4, 8, 10>; // 122.0
llOwnerSay((string)test.z); // 3.0を出力する
</syntaxhighlight>
</pre>
 
==== 外積、"%" 演算子 ====
<syntaxhighlight lang="lsl2">
vector v = <2, 3, 4> % <5, 6, 7>; // <-3, 6, -3>
</syntaxhighlight>
 
==== スカラー ====
ベクトルは、[[Float/ja]]または[[Integer/ja]]で乗算または除算してスケーリングできます。
 
ベクトルの各成分は、同じ値で乗算または除算されます。
<syntaxhighlight lang="lsl2">
vector v = <1, 2, 3> * 1.5; // <1.5, 3.0, 4.5>
vector v = <1, 2, 3> / 1.5; // <0.666667, 1.333333, 2.000000>
</syntaxhighlight>
 
==== 回転 ====
vector型は[[Quaternion/ja|クォータニオン]]の乗算または除算によって回転させることができます。
<syntaxhighlight lang="lsl2">
// Z軸(上向き)を中心に45度回転
rotation r = llEuler2Rot(<0, 0, 45> * DEG_TO_RAD);
 
// 東方向へ1メートルの方向を持つベクトル
vector v = <1, 0, 0>;
 
// 北東方向を向いたベクトル
vector rotated = v * r; // <0.707107, 0.707107, 0.000000>
 
// 南東方向を向いたベクトル
// (除算は逆方向に回転を行います)
vector rotated = v / r; // <0.707107, -0.707107, 0.000000>
</syntaxhighlight>
 
===便利なスニペット===
文字がVectorかチェックする
<source lang="lsl2">integer IsVector(string s) {
 
  list split = llParseString2List(s, [" "], ["<", ">", ","]);
  if(llGetListLength(split) != 7)//we must check the list length, or the next test won't work properly.
      return 0;
  return !((string)((vector)s) == (string)((vector)((string)llListInsertList(split, ["-"], 5))));
  //it works by trying to flip the sign on the Z element of the vector,
  //if it works or breaks the vector then the values won't match.
  //if the vector was already broken then the sign flip will have no affect and the values will match
  //we cast back to string so we can catch negative zero which allows for support of ZERO_VECTOR
 
}//Strife Onizuka</source>

Latest revision as of 16:02, 3 October 2023

Vector

vectorは3個の{floatの値のセットを含むデータ型(type)です。

成分

各要素は変数名の後に .x、.y、.zを付加することにより個別にアクセスできます。

vector vec = <1, 2, 3>;
float x = vec.x; // 1.0
float y = vec.y; // 2.0
float z = vec.z; // 3.0

用途

vector型は次のデータを保持するために使うことができます:

  • 位置: x, y, zの単位はm(メートル)
  • 速度: x, y, zはスピードをあらわします。 1秒あたりのm(メートル)
  • : Redはx、Greenはy、Blueはz

演算子

vector型は次の操作をサポートしています:

加算、"+" 演算子

vector v = <1, 2, 3> + <0.5, 0.0, 3>; // <1.5, 2.0, 6.0>

減算、"-" 演算子

vector v = <1, 1, 1> - <0.5, 0.0, 3>; // <0.5, 1.0, -2.0>

乗算 (内積)、 "*" 演算子

float f = <9, 2, 7> * <4, 8, 10>; // 122.0

外積、"%" 演算子

vector v = <2, 3, 4> % <5, 6, 7>; // <-3, 6, -3>

スカラー

ベクトルは、Float/jaまたはInteger/jaで乗算または除算してスケーリングできます。

ベクトルの各成分は、同じ値で乗算または除算されます。

vector v = <1, 2, 3> * 1.5; // <1.5, 3.0, 4.5>
vector v = <1, 2, 3> / 1.5; // <0.666667, 1.333333, 2.000000>

回転

vector型はクォータニオンの乗算または除算によって回転させることができます。

// Z軸(上向き)を中心に45度回転
rotation r = llEuler2Rot(<0, 0, 45> * DEG_TO_RAD);

// 東方向へ1メートルの方向を持つベクトル
vector v = <1, 0, 0>;

// 北東方向を向いたベクトル
vector rotated = v * r; // <0.707107, 0.707107, 0.000000>

// 南東方向を向いたベクトル
// (除算は逆方向に回転を行います)
vector rotated = v / r; // <0.707107, -0.707107, 0.000000>

便利なスニペット

文字がVectorかチェックする

integer IsVector(string s) {

   list split = llParseString2List(s, [" "], ["<", ">", ","]);
   if(llGetListLength(split) != 7)//we must check the list length, or the next test won't work properly.
       return 0;
   return !((string)((vector)s) == (string)((vector)((string)llListInsertList(split, ["-"], 5))));
   //it works by trying to flip the sign on the Z element of the vector,
   //if it works or breaks the vector then the values won't match.
   //if the vector was already broken then the sign flip will have no affect and the values will match
   //we cast back to string so we can catch negative zero which allows for support of ZERO_VECTOR

}//Strife Onizuka

Pages in category "LSL Vector/ja"

The following 6 pages are in this category, out of 6 total.