void Start() { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Capsule); capsParent = gameObject.GetComponentsInChildren <Transform>()[2]; for (int i = 0; i < num; i++) { float normalize = (float)i / num; Polar pos = new Polar(10f + Arithmos.SinNormalized(normalize * Arithmos.TWO_PI * 12f) * 5f, normalize * Arithmos.TWO_PI, 0f, Polar.BasePlane.XY); normalize *= 2f; normalize -= Mathf.Floor(normalize); normalize *= 2f; Quaternion rot = new Quaternion(0f, 0f, normalize - 1f, 1f); Instantiate(obj, pos, rot, capsParent); } Destroy(obj); obj = GameObject.CreatePrimitive(PrimitiveType.Sphere); spheParent = gameObject.GetComponentsInChildren <Transform>()[1]; for (int i = 0; i < num; i++) { float normalize = (float)i / num; Spherical pos = new Spherical(25f, normalize * Arithmos.TWO_PI, (normalize - 0.5f) * Arithmos.PI); Quaternion rot = new Quaternion(); Instantiate(obj, pos, rot, spheParent); } Destroy(obj); }
/// <summary> /// Writes time-tagged <see cref="Spherical"/> values as an array in [Time, Clock, Cone, Magnitude] order. /// Times are epoch seconds since an epoch that is determined from the first date to be written. /// The epoch property is written as well. /// </summary> /// <param name="output">The stream to which to write the array.</param> /// <param name="propertyName">The name of the property to write.</param> /// <param name="dates">The dates at which the value is specified.</param> /// <param name="values">The corresponding value for each date.</param> /// <param name="startIndex">The index of the first element to use in the <paramref name="values"/> collection.</param> /// <param name="length">The number of elements to use from the <paramref name="values"/> collection.</param> public static void WriteSpherical(CesiumOutputStream output, string propertyName, IList <JulianDate> dates, IList <Spherical> values, int startIndex, int length) { if (dates.Count != values.Count) { throw new ArgumentException(CesiumLocalization.MismatchedNumberOfDatesAndValues, "values"); } JulianDate epoch = GetAndWriteEpoch(output, dates, startIndex, length); output.WritePropertyName(propertyName); output.WriteStartSequence(); int last = startIndex + length; for (int i = startIndex; i < last; ++i) { output.WriteValue(epoch.SecondsDifference(dates[i])); Spherical value = values[i]; output.WriteValue(value.Clock); output.WriteValue(value.Cone); output.WriteValue(value.Magnitude); output.WriteLineBreak(); } output.WriteEndSequence(); }
void Update() { double latitude = Input.location.lastData.latitude; double longitude = Input.location.lastData.longitude; foreach (var iManager in this.celestialManagers) { double deltaTheta, deltaPhi; var position = iManager.CalculatePosition(DateTime.UtcNow, latitude, longitude); double distance = CelestialScale.MoonScale(0.04f).AproxDistance; Vector3 v = Spherical.SphericalToCartesian(Math.PI / 2 - position.altitude, position.azimuth, distance /* moonPosition.distance / 405629.76174948126*/); Vector3 cameraDirection = Camera.main.transform.rotation * Vector3.forward; CalculateHelper(cameraDirection, v, out deltaPhi, out deltaTheta); double angle = Math.Atan2(deltaTheta, -deltaPhi) + Math.PI; double carboardRadius = 25f; double module = Math.Sqrt(deltaTheta * deltaTheta + deltaPhi * deltaPhi); if (module < (4 * Math.PI) / 180) { moonTargetCardboard.rectTransform.localPosition = new Vector3(200f, 200f, 0f); Application.LoadLevel("GoToTheMoonScene"); } else { moonTargetCardboard.rectTransform.localPosition = new Vector3((float)(1.5f * carboardRadius * Math.Cos(angle)), (float)(carboardRadius * Math.Sin(angle)), 0f); } } }
//Adds an vertical angle (theta) of the target vector public static Vector3 AddTheta(this Vector3 target, float theta) { Spherical spherical = (Spherical)target; spherical.theta += theta; return((Vector3)spherical); }
public static Spherical Lerp(Spherical sph1, Spherical sph2, float k) { return(new Spherical( Mathf.Lerp(sph1.rho, sph2.rho, k), Mathf.Lerp(sph1.theta, sph2.theta, k), Mathf.Lerp(sph1.phi, sph2.phi, k))); }
protected void Update() { double latitude = Input.location.lastData.latitude; double longitude = Input.location.lastData.longitude; var position = this.celestialManager.CalculatePosition(DateTime.UtcNow, latitude, longitude); double distance = CelestialScale.MoonScale(0.04f).AproxDistance; Vector3 v = Spherical.SphericalToCartesian(Math.PI / 2 - position.altitude, position.azimuth, distance /* moonPosition.distance / 405629.76174948126*/); Spherical vSpherical = (Spherical)v; Vector3 titlePosition = v.AddTheta(-Mathf.PI / 16); //titlePosition.y+=1.5f; myTextMesh.text = String.Format("{0}\n{1}\n{2} Km.", celestialManager.Name, celestialManager.Status, distance); myText.transform.position = titlePosition; myText.transform.rotation = Quaternion.EulerAngles(0, vSpherical.phi, 0); transform.rotation = Quaternion.EulerAngles(0, vSpherical.phi + Mathf.PI / 2, 0); transform.position = v; }
/// <summary> /// Writes a <see cref="Spherical"/> value as an array in Clock, Cone, Magnitude order. /// </summary> /// <param name="output">The stream to which to write the value.</param> /// <param name="value">The value to write.</param> public static void WriteSpherical(CesiumOutputStream output, Spherical value) { output.WriteStartSequence(); output.WriteValue(value.Clock); output.WriteValue(value.Cone); output.WriteValue(value.Magnitude); output.WriteEndSequence(); }
public void Theta_outside_of_0_to_180_range_wraps(double rawTheta, double expected) { var phi = Angle.From(Degrees.Ninety); var theta = Angle.From(Degrees.FromRaw(rawTheta)); var point = new Spherical(phi, theta); Assert.Equal(Degrees.FromRaw(expected), point.Theta.Degrees); }
public Vector3 GetRandDirection(Spherical directionPivot, Spherical extends) { float jitHeading = -extends.Phi + (float)_rand.NextDouble() * (2 * extends.Phi); float jitPith = -extends.Theta + (float)_rand.NextDouble() * (2 * extends.Theta); Vector3 direction = Spherical.ToCartesian(directionPivot.Theta + jitPith, directionPivot.Phi + jitHeading); return(direction); }
void Start() { polarCoord = new Polar(); polarCylindrical = gameObject.GetComponentsInChildren <Transform>()[0]; sphericalCoord = new Spherical(); spherical = gameObject.GetComponentsInChildren <Transform>()[1]; }
public void Evaluate() { Spherical function = new Spherical(); Vector v1 = new Vector(new double[] { 1, 2, 3 }); Vector v2 = new Vector(new double[] { 0, 0, 0 }); Assert.AreEqual(14, function.Evaluate(v1)); Assert.AreEqual(0, function.Evaluate(v2)); }
public void Default_r_value_is_one() { var phi = Angle.From(Degrees.Ninety); var theta = Angle.From(Degrees.Ninety); var point = new Spherical(phi, theta); Assert.Equal(1, point.R); }
public Vector3 GetRandDirection() { float jitPith = (float)_rand.NextDouble() * Numerics.PI; float jitHeading = (float)_rand.NextDouble() * Numerics.TwoPI; Vector3 direction = Spherical.ToCartesian(jitPith, jitHeading); return(direction); }
public void Can_create(double rawPhi, double rawTheta, double r) { var phi = Angle.From(Degrees.FromRaw(rawPhi)); var theta = Angle.From(Degrees.FromRaw(rawTheta)); var point = new Spherical(phi, theta, r); Assert.Equal(phi, point.Phi); Assert.Equal(theta, point.Theta); Assert.Equal(r, point.R); }
public static Spherical CartesianToSpherical(Vector3 cartesian) { Spherical result = new Spherical(); result.radius = Mathf.Sqrt(cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z); result.theta = Mathf.Acos(cartesian.y / result.radius); //result.phi = Mathf.Atan(cartesian.x / cartesian.z); result.phi = Mathf.Atan2(cartesian.x, cartesian.z); return(result); }
private Spherical GetSpherical(float scaleFactor, float r, float g, float b) { var spherical = new Spherical(); spherical.ParallelCount = 80; spherical.Texture = new ColorTexture(r, g, b, 1.0f); spherical.Material = GetMaterial(); spherical.Transform = GetScalingAndRandomTranslation(scaleFactor); return(spherical); }
public void Error() { ExpandedDecorator decorator = new ExpandedDecorator(); IContinuousFunction function = new Spherical(); decorator.Function = function; decorator.SplitSize = 3; Vector v1 = new Vector(new double[] { 0, 0 }); Assert.Throws <ArgumentException>(() => decorator.Evaluate(v1)); }
public void Can_convert_cartesian_to_spherical(double x, double y, double z, double phi, double theta, double r) { var point = new Cartesian3D(x, y, z); var result = Conversion.Spherical.From(point); var expected = new Spherical( phi: Angle.From(Degrees.FromRaw(phi)), theta: Angle.From(Degrees.FromRaw(theta)), r: r); Assert.Equal(expected, result); }
public void Can_convert_spherical_to_cartesian(double phi, double theta, double r, double x, double y, double z) { var spherical = new Spherical( phi: Angle.From(Degrees.FromRaw(phi)), theta: Angle.From(Degrees.FromRaw(theta)), r: r); var cartesian = Conversion.Cartesian3D.From(spherical); var expected = new Cartesian3D(x, y, z); Assert.Equal(expected, cartesian); }
static AstroVector DirectionVector(AstroTime time, Observer observer, double altitude, double azimuth) { // Convert horizontal angles to a horizontal unit vector. var hor = new Spherical(altitude, azimuth, 1.0); AstroVector hvec = Astronomy.VectorFromHorizon(hor, time, Refraction.None); // Find the rotation matrix that converts horizontal vectors to equatorial vectors. RotationMatrix rot = Astronomy.Rotation_HOR_EQD(time, observer); // Rotate the horizontal (HOR) vector to an equator-of-date (EQD) vector. AstroVector evec = Astronomy.RotateVector(rot, hvec); return(evec); }
public static void CartesianToSpherical(Vector3 cartesian, out Spherical spherical) //changes cartesian to spherical { if (cartesian.x == 0) { cartesian.x = Mathf.Epsilon; } spherical.radius = Mathf.Sqrt(cartesian.x * cartesian.x + cartesian.y * cartesian.y + cartesian.z * cartesian.z); spherical.theta = Mathf.Atan(cartesian.z / cartesian.x); if (cartesian.x < 0) { spherical.theta += Mathf.PI; } spherical.phi = Mathf.Asin(cartesian.y / spherical.radius); }
static void Main(string[] args) { // 球坐标转为笛卡尔坐标 var spherical0 = new Spherical(Math.PI / 4, Math.PI / 8, 100.0); var cartesian0 = new Cartesian(spherical0); Console.WriteLine("球坐标:{0};笛卡尔坐标:{1}", spherical0, cartesian0); // 笛卡尔坐标归一化 UnitCartesian unitCartesian1 = cartesian0.Normalize(); Console.WriteLine("单位矢量笛卡尔坐标:{0}", unitCartesian1); // 地图坐标转为笛卡尔坐标 var cartographic2 = new Cartographic(Trig.DegreesToRadians(120), Trig.DegreesToRadians(30), 100); EarthCentralBody earth = CentralBodiesFacet.GetFromContext().Earth; Cartesian cartesian2 = earth.Shape.CartographicToCartesian(cartographic2); Console.WriteLine("地图坐标:{0};笛卡尔坐标:{1}", cartographic2, cartesian2); // 笛卡尔坐标转为地图坐标 Cartographic cartographic3 = earth.Shape.CartesianToCartographic(cartesian2); Console.WriteLine("笛卡尔坐标:{0};地图坐标:{1}", cartesian2, cartographic3); // 新坐标系绕原坐标系z轴旋转90度,原向量(1,0,0) var vector4 = new Cartesian(1, 0, 0); var rotation4 = new ElementaryRotation(AxisIndicator.Third, Trig.DegreesToRadians(90)); Cartesian newVector4 = new Matrix3By3(rotation4).Multiply(vector4); Console.WriteLine("旋转前:{0};旋转后:{1}", vector4, newVector4); // 欧拉旋转 var vector5 = new Cartesian(1, 0, 0); double angle = Trig.DegreesToRadians(90); var euler = new EulerSequence(angle, angle, angle, EulerSequenceIndicator.Euler321); Cartesian newVector5 = new Matrix3By3(euler).Multiply(vector5); Console.WriteLine("旋转前:{0};旋转后:{1}", vector5, newVector5); // 偏航俯仰翻滚旋转 var vector6 = new Cartesian(1, 0, 0); double angle6 = Trig.DegreesToRadians(90); var ypr = new YawPitchRoll(angle, angle, angle, YawPitchRollIndicator.YPR); Cartesian newVector6 = new Matrix3By3(ypr).Multiply(vector6); Console.WriteLine("旋转前:{0};旋转后:{1}", vector6, newVector6); Console.Read(); }
public override void Update() { base.Update(); Spherical s = new Spherical(); foreach (var l in lights) { s.Set(l.Node.Position - center); s.el.z += 0.001f; s.Restrict(); var v = s.GetVec(); l.Node.Position = center + v; } }
static int Search( out double ecliptic_longitude_crossing, out Spherical hor_crossing, AstroTime time, RotationMatrix rot_ecl_hor, double e1, double e2) { int error; double e3; Spherical h3; const double tolerance = 1.0e-6; /* one-millionth of a degree is close enough! */ /* * Binary search: find the ecliptic longitude such that the horizontal altitude * ascends through a zero value. The caller must pass e1, e2 such that the altitudes * bound zero in ascending order. */ ecliptic_longitude_crossing = 1.0e+99; // initialize with impossible value hor_crossing = new Spherical(); for (;;) { e3 = (e1 + e2) / 2.0; error = HorizontalCoords(out h3, e3, time, rot_ecl_hor); if (error != 0) { return(error); } if (Math.Abs(e2 - e1) < tolerance) { /* We have found the horizon crossing within tolerable limits. */ ecliptic_longitude_crossing = e3; hor_crossing = h3; return(0); } if (h3.lat < 0.0) { e1 = e3; } else { e2 = e3; } } }
public void Evaluate() { ExpandedDecorator decorator = new ExpandedDecorator(); IContinuousFunction function = new Spherical(); decorator.Function = function; decorator.SplitSize = 1; Vector v1 = new Vector(new double[] { 0, 0 }); Vector v2 = new Vector(new double[] { 1, 1 }); Vector v3 = new Vector(new double[] { 1, 2, 3 }); Assert.AreEqual(0, decorator.Evaluate(v1)); Assert.AreEqual(4, decorator.Evaluate(v2)); Assert.AreEqual(28, decorator.Evaluate(v3)); }
public void Can_convert_spherical_to_geodesic(double phi, double theta, double r, double lat, double lon) { var point = new Spherical( phi: Angle.From(Degrees.FromRaw(phi)), theta: Angle.From(Degrees.FromRaw(theta)), r: r); var result = Conversion.Geodesic.From(point); var expected = new Geodesic( latitude: Angle.From(Degrees.FromRaw(lat)), longitude: Angle.From(Degrees.FromRaw(lon)) ); Assert.Equal(expected, result); }
void CalculateHelper(Vector3 camera, Vector3 target, out double deltaPhi, out double deltaTheta) { Spherical sCamera = (Spherical)camera; Spherical sTarget = (Spherical)target; deltaPhi = sTarget.phi - sCamera.phi; deltaTheta = sTarget.theta - sCamera.theta; if (deltaPhi > Math.PI) { deltaPhi = -2 * Math.PI + deltaPhi; } else if (deltaPhi < -Math.PI) { deltaPhi = 2 * Math.PI + deltaPhi; } }
public void Evaluate() { CompositeDecorator decorator = new CompositeDecorator(); IContinuousFunction function = new Spherical(); decorator.InnerFunction = function; decorator.OuterFunction = function; Vector v1 = new Vector(new double[] { 0, 0 }); Vector v2 = new Vector(new double[] { 1, 1 }); Vector v3 = new Vector(new double[] { 1, 2, 3 }); Assert.AreEqual(0, decorator.Evaluate(v1)); Assert.AreEqual(4, decorator.Evaluate(v2)); Assert.AreEqual(196, decorator.Evaluate(v3)); }
private void CreateLights() { _lights = new Frame[6]; Random ran = new Random(); Color3[] colors = new Color3[8] { new Color3(Color.Yellow.ToArgb()), new Color3(Color.Red.ToArgb()), new Color3(Color.Green.ToArgb()), new Color3(Color.LightCoral.ToArgb()), new Color3(Color.DarkBlue.ToArgb()), new Color3(Color.Gray.ToArgb()), new Color3(Color.IndianRed.ToArgb()), new Color3(Color.LightSalmon.ToArgb()) }; float step = Numerics.TwoPI / _lights.Length; Spherical spherical = new Spherical(Numerics.PIover2, 0); for (int i = 0; i < _lights.Length; i++) { var light = new Light() { Diffuse = colors[i % 8], //Diffuse = new Vector3((float)ran.NextDouble(),(float)ran.NextDouble(),(float)ran.NextDouble()), Specular = new Vector3(0.2f, 0.2f, 0.2f), Type = LightType.Point, Enable = true }; spherical.Phi = step * i; var pos = spherical.ToCartesian() * 300; pos.Y = 50; var instance = new FrameLight(light); var node = SceneManager.Scene.Create("light" + i, instance, localPosition: pos, localRotationEuler: Euler.FromDirection(new Vector3(0, -1, 0)), localScale: new Vector3(1, 1, 1)); SceneManager.Scene.Dynamics.Add(new Dynamic(x => { Frame n = node; n.LocalPosition = Vector3.TransformCoordinates(n.LocalPosition, Matrix.RotationY(Numerics.ToRadians(1))); n.ComputeLocalPose(); n.CommitChanges(); })); _lights[i] = node; } }
static int HorizontalCoords( out Spherical hor, double ecliptic_longitude, AstroTime time, RotationMatrix rot_ecl_hor) { var eclip = new Spherical( 0.0, /* being "on the ecliptic plane" means ecliptic latitude is zero. */ ecliptic_longitude, 1.0 /* any positive distance value will work fine. */ ); /* Convert ecliptic angular coordinates to ecliptic vector. */ AstroVector ecl_vec = Astronomy.VectorFromSphere(eclip, time); /* Use the rotation matrix to convert ecliptic vector to horizontal vector. */ AstroVector hor_vec = Astronomy.RotateVector(rot_ecl_hor, ecl_vec); /* Find horizontal angular coordinates, correcting for atmospheric refraction. */ hor = Astronomy.HorizonFromVector(hor_vec, Refraction.Normal); return(0); /* success */ }