Browse Source

Merge pull request #10253 from Mugen87/dev

Cylindrical: Support for Cylindrical Coordinates
Mr.doob 8 years ago
parent
commit
984a14011d
6 changed files with 141 additions and 1 deletions
  1. 62 0
      docs/api/math/Cylindrical.html
  2. 5 0
      docs/api/math/Vector3.html
  3. 1 0
      docs/list.js
  4. 1 0
      src/Three.js
  5. 61 0
      src/math/Cylindrical.js
  6. 11 1
      src/math/Vector3.js

+ 62 - 0
docs/api/math/Cylindrical.html

@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html lang="en">
+	<head>
+		<meta charset="utf-8" />
+		<base href="../../" />
+		<script src="list.js"></script>
+		<script src="page.js"></script>
+		<link type="text/css" rel="stylesheet" href="page.css" />
+	</head>
+	<body>
+		<h1>[name]</h1>
+
+		<div class="desc">A point's cylindrical coordinates.</div>
+
+
+		<h2>Constructor</h2>
+
+
+		<h3>[name]( [page:Float radius], [page:Float theta], [page:Float y] )</h3>
+		<div>
+		radius -- [page:Float] distance from the origin to a point in the x-z plane<br />
+		theta -- [page:Float] counterclockwise angle in the x-z plane measured in radians from the positive z-axis<br />
+		y -- [page:Float] height above the x-z plane
+		</div>
+
+
+		<h2>Properties</h2>
+
+		<h3>[property:Float radius]</h3>
+
+		<h3>[property:Float theta]</h3>
+
+		<h3>[property:Float y]</h3>
+
+
+		<h2>Methods</h2>
+
+		<h3>[method:Cylindrical set]( [page:Float radius], [page:Float theta], [page:Float y] ) [page:Cylindrical this]</h3>
+		<div>
+		Sets values of this cylindrical's component coordinates.
+		</div>
+
+		<h3>[method:Cylindrical copy]( [page:Cylindrical c] ) [page:Cylindrical this]</h3>
+		<div>
+		Copies value of *c* to this cylindrical.
+		</div>
+
+		<h3>[method:Cylindrical clone]() [page:Cylindrical this]</h3>
+		<div>
+		Clones this cylindrical.
+		</div>
+
+		<h3>[method:Cylindrical setFromVector3]( [page:Vector3 v] ) [page:Cylindrical this]</h3>
+		<div>
+		Sets this object from the vector *v*.
+		</div>
+
+		<h2>Source</h2>
+
+		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
+	</body>
+</html>

+ 5 - 0
docs/api/math/Vector3.html

@@ -202,6 +202,11 @@
 		Sets this vector from the spherical coordinates *s*.
 		</div>
 
+		<h3>[method:Vector3 setFromCylindrical]( [page:Cylindrical c] ) [page:Vector3 this]</h3>
+		<div>
+		Sets this vector from the cylindrical coordinates *c*.
+		</div>
+
 		<h3>[method:Vector3 clamp]( [page:Vector3 min], [page:Vector3 max] ) [page:Vector3 this]</h3>
 		<div>
 		min -- [page:Vector3] <br />

+ 1 - 0
docs/list.js

@@ -239,6 +239,7 @@ var list = {
 			[ "Box2", "api/math/Box2" ],
 			[ "Box3", "api/math/Box3" ],
 			[ "Color", "api/math/Color" ],
+			[ "Cylindrical", "api/math/Cylindrical" ],
 			[ "Euler", "api/math/Euler" ],
 			[ "Frustum", "api/math/Frustum" ],
 			[ "Interpolant", "api/math/Interpolant" ],

+ 1 - 0
src/Three.js

@@ -102,6 +102,7 @@ export { Triangle } from './math/Triangle.js';
 export { Spline } from './math/Spline.js';
 export { _Math as Math } from './math/Math.js';
 export { Spherical } from './math/Spherical.js';
+export { Cylindrical } from './math/Cylindrical.js';
 export { Plane } from './math/Plane.js';
 export { Frustum } from './math/Frustum.js';
 export { Sphere } from './math/Sphere.js';

+ 61 - 0
src/math/Cylindrical.js

@@ -0,0 +1,61 @@
+/**
+ * @author Mugen87 / https://github.com/Mugen87
+ *
+ * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
+ *
+ */
+
+function Cylindrical( radius, theta, y ) {
+
+	this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
+	this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
+	this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
+
+	return this;
+
+}
+
+Cylindrical.prototype = {
+
+	constructor: Cylindrical,
+
+	set: function ( radius, theta, y ) {
+
+		this.radius = radius;
+		this.theta = theta;
+		this.y = y;
+
+		return this;
+
+	},
+
+	clone: function () {
+
+		return new this.constructor().copy( this );
+
+	},
+
+	copy: function ( other ) {
+
+		this.radius = other.radius;
+		this.theta = other.theta;
+		this.y = other.y;
+
+		return this;
+
+	},
+
+	setFromVector3: function( vec3 ) {
+
+		this.radius = Math.sqrt( vec3.x * vec3.x + vec3.z * vec3.z );
+		this.theta = Math.atan2( vec3.x, vec3.z );
+		this.y = vec3.y;
+
+		return this;
+
+	}
+
+};
+
+
+export { Cylindrical };

+ 11 - 1
src/math/Vector3.js

@@ -79,7 +79,7 @@ Vector3.prototype = {
 			default: throw new Error( 'index is out of range: ' + index );
 
 		}
-		
+
 		return this;
 
 	},
@@ -685,6 +685,16 @@ Vector3.prototype = {
 
 	},
 
+	setFromCylindrical: function( c ) {
+
+		this.x = c.radius * Math.sin( c.theta );
+		this.y = c.y;
+		this.z = c.radius * Math.cos( c.theta );
+
+		return this;
+
+	},
+
 	setFromMatrixPosition: function ( m ) {
 
 		return this.setFromMatrixColumn( m, 3 );