Classiclll's Blog

an old boy

re-chestnut君への謝辞=Rodの妄想

re-chestnut君への謝辞=Rodの妄想


元塾講師、有志、あるいは私自身への宿題でre-chestnut君が解いてくれた【問3】の解法を活用すべく、新しいクラスRodを妄想中。

クラス Rod ー 3次元空間の直線のモデル

位置ベクトルのモデルであるLocに比べると操作のバリエーションは少ないけど、各々の内容は遥かに濃い。とりあえず下記のようなイメージ
stern()=艢(とも)  :基点の位置
fore()=前方(ぜんぽう):長さ1の単位ベクトル
bow() =舳先(へさき) :(直線の)方向ベクトルを現在の長さ(length)だけ延長したところにある点
at(t)=tにある位置  :(直線の)方向ベクトルを長さtだけ延長したところにある点
length()=全長    ;この【線分】の長さ

つぎの三っつのメソッドはre-chestnut君による解の公式の成果。(多謝)
Rod nearest(Rod to) // thisとtoのあいだの最短線分、長さが0なら交差している
float dist(Rod to) // 二つの直線間の距離(3次元空間上での最近接距離)
boolean crossing(Rod to) // 直線toと交差するか?(最近接距離がゼロか?)
で、API
* Class Rod, the model of partial line on the 3D space,
 * 			spanned from it's stern to it's bow
 *					created by Classiclll, 6/28/2008
 *  Rod(Loc s, Loc b)			// only constructor you can use
 *  	Loc at(float t)			// location at t, at(0):stern, at(me.length):bow
	Rod move(Loc to)			// move stern to "to"
	Rod shift(Loc diff)		// shift stern by "diff"
	Rod shiftI(Loc diff)		// inverse shift
	Rod scale(float factor)	// scale the size of me by factor
	Rod scaleI(float factor)	// inverse scaling
	Loc intersect2D(Rod to) 	// intersect position on the x-y plane
	float signedDist2D(Rod pt)// distance with sign of left/right side on the x-y plane
	float dist2D(Loc pt)		// distance between "me" and "pt" on the x-y plane
	Rod ortho(Loc pt)		// the shortest rod connecting from "me" to "pt"
	Rod nearest(Rod to)		// the shortest rod connecting from "me" to "to"
	float dist(Loc pt)		// distance between "me" and "pt"
	boolean having(Loc pt)	// is "me" having "pt" on myself ?
	float dist(Rod to)		// least distance between "me" and line "to"
	boolean crossing(Rod to)// are "me" and "to" crossing each other ?
	float length()			// length of me
	Loc stern()				// location of the stern of me
	Loc bow()				// location of the bow of me
	Loc fore()				// foward direction of me, the unit vector
	Boolean equals(Rod to)
	String toString()
ついでに、

静的クラス l4p5 ー Loc, Rod, PImageのための描画ユーティリティ

Processingのsketchでは、例えば
Loc p=new Loc(1,2,3), q=new Loc(4,2,4);
l4p5.line(p, q);
のように使えるはず
* class l4p5, P5 drawing utilities for package Loc 
 *           coded by Classiclll on 08/07/20
[initial setting, always needed]
 *  setL4p5(PApplet parent)
[Processing's primitives]
	lline2D(Loc s, Loc t)
	lline2D(Rod r)
 	lline(Loc s, Loc t)
	lline(Rod r)
	lvertex(Loc l)
	lvertex(Loc l, float u, float v) 
	lvertex2D(Loc l)
 	lvertex2D(Loc l, float u, float v) 
	lbezierVertex(Loc l, Loc m, float x, float y, float z)
	lbezierVertex2D(Loc l, Loc m, float x, float y)
	lellipse(Loc l, float width, float height)
	lellipse(Rod r)
	lrect(Loc l, float width, float height)
	lrect(Rod r)
	lpoint(Loc l)
	lpoint2D(Loc l)
	lbox(Loc l, float width, float height, float depth)
	lbox(Rod r)
	lsphere(Loc l, float radius)
	lsphere(Rod r)
[Extended stufs]
	lpolygon(Loc[] at)
	lpolygon(Loc[] at, PImage img)
[Texture Mapped 3D Primitives.    coded by Classiclll on 5/1/2006]
	"dim" is the degree of detail of each shapes (positive odd number)
	[Capsules]
	void ltmdSphere(float radius, PImage img)
	void ltmdOctahedron(float radius, PImage img)
	void ltmdBarrel(float radius, PImage img)
	void ltmdCapsule(int dim, float radius, PImage img)
	[Tubes]
	void ltmdBox(float len, PImage img)
	void ltmdHexapole(float radius, float len, PImage img)
	void ltmdTube(int dim, float radius, float len, PImage img)
	[Cones]
	void ltmdTetra(float len, PImage img)
	void ltmdCone(float radius, float len, PImage img)
	void ltmdCone(int dim, float radius, float len, PImage img)
	[Torus]
		// To Do

【7月21日修正:最終版】


Processing については、
日本語サポートサイトからたどれるP5インフォメーション→言語が参考になる。
(解説してあるのは一昔前の版だから注意が必要だけど、loop()→draw()の読み替えだけで大抵OK)
・山本徹(thoru)さんがFunProce55ingで解説してくれている。(【簡潔】で【わかり易く】、【楽しい】解説)
例題集は習作集と区別するためにこちらに置いている。
・P5のスケッチからアプレットを作り、【ジオシティーズ】にアップする手順をまとめたので、参考に。
WiiRemoteアクセスライブラリWrj4P5はここ