public TVector2 Copy() { TVector2 ret = new TVector2(_v.x, _v.y, Tag); return ret; }
public TVector2 this[int index] { get { switch (index) { case 0: return this.a; case 1: return this.b; default: throw new System.IndexOutOfRangeException("Invalid LineSegment2D index!"); } } set { switch (index) { case 0: this.a = value; break; case 1: this.b = value; break; default: throw new System.IndexOutOfRangeException("Invalid LineSegment2D index!"); } } }
public TVector2 this[int index] { get { switch (index) { case 0: return this.a; case 1: return this.b; case 2: return this.c; case 3: return this.d; default: throw new System.IndexOutOfRangeException("Invalid Quad2D index!"); } } set { switch (index) { case 0: this.a = value; break; case 1: this.b = value; break; case 2: this.c = value; break; case 3: this.d = value; break; default: throw new System.IndexOutOfRangeException("Invalid Quad2D index!"); } } }
public string Accept(TVector2 type, string bufName) { return($"{bufName}.ReadVector2()"); }
public DType Accept(TVector2 type, string x) { throw new NotSupportedException(); }
public static DType CreateVector(TVector2 type, string x) { var values = SplitVectorString(x); return(new DVector2(new System.Numerics.Vector2(float.Parse(values[0]), float.Parse(values[1])))); }
public string Accept(TVector2 type, string fieldName, string tablesName) { throw new NotImplementedException(); }
public Triangle3[] GetStraightSpokePlane (TVector3 origin, float zOffset, string Tag1, string Tag2) { System.Collections.Generic.List<Triangle3> tris = new List<Triangle3> (); //Calc the angle to sweep... float inctheta = 2 * Mathf.PI / ((float)_spokeCount); float theta = 0.0f; float adjAngle = 0.0f; System.Collections.Generic.List<LineSegment2D> spokelines = new System.Collections.Generic.List<LineSegment2D> (); for (int i = 0; i < (_spokeCount + 1); i++) { adjAngle = inctheta; TVector2 pt1; TVector2 pt2; if(_hubRadius !=0){ pt1 = new TVector2((_hubRadius) * Mathf.Cos(theta) + origin.Value.x, (_hubRadius) * Mathf.Sin(theta) + origin.Value.y, VERT_SpokeEdgeTop); }else{ pt1 = new TVector2(origin.Value.x, origin.Value.y, VERT_SpokeEdgeTop); } pt2 = new TVector2(_ringRadius * Mathf.Cos(theta) + origin.Value.x, _ringRadius * Mathf.Sin(theta) + origin.Value.y, VERT_SpokeEdgeTop); LineSegment2D ls = new LineSegment2D (); ls.a = pt1; ls.b = pt2; spokelines.Add (ls); theta += (adjAngle); } theta = 0.0f; for (int i = 0; i < (_spokeCount); i++) { Quad3D q3; var q2 = CreateQuadFromLineSegment (spokelines [i], _spokeWidthInner, _spokeWidthOuter); q3 = new Quad3D().Create(q2, origin.Value.z); q3.Tag = Tag1; var qtris = q3.GetTris (); qtris[0].Tag = q3.Tag; qtris[0].SortOrder = _triOrder; _triOrder += 2; qtris[1].Tag = Tag2; qtris[1].SortOrder = _triOrder; _triOrder += 2; tris.AddRange (qtris); } return tris.ToArray (); }
public virtual void Accept(TVector2 type, T x) { DoAccept(type, x); }
public string Accept(TVector2 type) { return("bright.math.Vector2"); }
public bool Accept(TVector2 type, TType x, Dictionary <DefTypeBase, bool> y, HashSet <DefTypeBase> z) { return(true); }
public DType Accept(TVector2 type, XElement x, DefAssembly ass) { return(DataUtil.CreateVector(type, x.Value)); }
public override bool Accept(TVector2 type) { return(true); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { TVector2 tObj = serializer.Deserialize <TVector2>(reader); return(new Vector2(tObj.x, tObj.y)); }
public string Accept(TVector2 type) { return("VECTOR2"); }
public override string Accept(TVector2 type) { return("Vector2"); }
public string Accept(TVector2 type, string fieldName, string logType) { return($"{fieldName} = default;"); }
public CircleEvent(TVector2 circumcenter, TNumber radius, Node swallowedParabolaNode) { Circumcenter = circumcenter; Radius = radius; SwallowedParabolaNode = swallowedParabolaNode; }
public string Accept(TVector2 type) { return($"math.Vector2"); }
public string Accept(TVector2 type, string bufName, string fieldName) { return($"{fieldName} = {bufName}.readVector2();"); }
public EdgeRayData(bool isOriginBounded, TVector2 origin, TVector2 direction) { IsOriginBounded = isOriginBounded; Origin = origin; Direction = direction; }
TVector2[] BuildUVs (System.Collections.Generic.List<Triangle3> tris) { _ToothPerim = GetToothPermiter(tris, new string[]{TRI_SideOuterTop}); //Build Uv's var uvs = new List<TVector2>(); //Build uvs for planes... var tbounds = GetUVBoundaries(tris,new string[]{TRI_GearPlaneTopA1, TRI_GearPlaneTopA2, TRI_GearPlaneTopB, TRI_GearPlaneTopC, TRI_GearPlaneTopD, TRI_GearPlaneTopE}); //Get max extents for the verticies. var tmin = tbounds.min; var tbsz = tbounds.size; var bbounds = GetUVBoundaries(tris,new string[]{TRI_GearPlaneBottomA1, TRI_GearPlaneBottomA2, TRI_GearPlaneBottomB, TRI_GearPlaneBottomC, TRI_GearPlaneBottomD, TRI_GearPlaneBottomE}); //Get max extents for the verticies. var bmin = bbounds.min; var bbsz = bbounds.size; var hubRange = GetUVBoundaries(tris, new string[]{TRI_HubBottom, TRI_HubSideBottom, TRI_HubTop, TRI_HubSideTop}); var hubMin = hubRange.min; var hubSz = hubRange.size; var spokeRange = GetUVBoundaries(tris, new string[]{TRI_SolidSpokePlaneTop, TRI_SolidSpokePlaneBottom, TRI_SpokeTop1, TRI_SpokeTop2, TRI_SpokeBottom1, TRI_SpokeBottom2, TRI_SpokeSideBottom, TRI_SpokeSideTop}); var spokeMin = spokeRange.min; var spokeSz = spokeRange.size; //Get UV 'Buckets' float pad = .01f; //Padding float hs = 1.0f / (_ToothPerim); float vs = hs; float toph = Mathf.Max(tbsz.x, tbsz.y) * vs; //(2.0f * _outerRadius * vs); // Top Height Scaled float bottomh = Mathf.Max(bbsz.x, bbsz.y) * vs;//(2.0f * _outerRadius * vs * _topScale); // BottomHeight Scaled float gh = _height * vs;//_height * vs; //Gear Height Scaled float hh = _hubHeight * vs; //Hub Height Scaled float spokeh = spokeSz.y * vs; //(2.0f * _ringRadius * vs); float spokew = spokeSz.x * vs; float sidespokeh = (_height - (_spokeIndent)) * vs * 2.0f; //float hubcaph = (2.0f * Mathf.Sqrt((_spokeWidthInner) * (_spokeWidthInner) + (_hubRadius * _hubRadius)) * vs); //??? float hubcaph = Mathf.Max(hubSz.x, hubSz.y) * vs; Rect topbounds = new Rect(pad, 1.0f - pad - toph, toph, toph); Rect bottombounds = new Rect(pad, topbounds.y - bottomh - pad, bottomh, bottomh); Rect topspokebounds = new Rect(topbounds.x + topbounds.width + pad, 1.0f - pad - spokeh, spokew, spokeh); Rect bottomspokebounds = new Rect(topspokebounds.x, topspokebounds.y - pad - spokeh, spokew, spokeh); float perimstarty = bottombounds.y; if (perimstarty > bottomspokebounds.y){ perimstarty = bottomspokebounds.y; } Rect perimbounds = new Rect(pad, perimstarty - 2.0f * pad - gh, 1.0f - 2.0f * pad, gh); Rect ringbounds = new Rect(pad, perimbounds.y - pad - gh, 1.0f - 2.0f * pad, gh); Rect hubbounds = new Rect(pad, ringbounds.y - pad - hh, 1.0f - 2.0f * pad, hh); Rect tophubcapbounds = new Rect(topspokebounds.x + topspokebounds.width + pad, topspokebounds.y, hubcaph, hubcaph); Rect bottomhubcapbounds = new Rect(tophubcapbounds.x, tophubcapbounds.y - pad - hubcaph, hubcaph, hubcaph); Rect spokesidebounds = new Rect(pad, pad, 1.0f - 2.0f * pad, sidespokeh + pad); float lastoutertopx = perimbounds.x; float lastouterbottomx = perimbounds.x; float lastinnertopx = ringbounds.x; float lastinnerbottomx = ringbounds.x; float lasthubbottomx = hubbounds.x; float lasthubtopx = hubbounds.x; float lastspokesidetopx = spokesidebounds.x; float lastspokesidebottomx = spokesidebounds.x; //For top plane verts, go through and calc the UV space. foreach (Triangle3 tri in tris) { float x = 0.0f; float y = 0.0f; //float xScale = (_ToothPerim); //float yScale = xScale; var BottomTagList = new string[] {TRI_GearPlaneBottomA1, TRI_GearPlaneBottomA2, TRI_GearPlaneBottomB, TRI_GearPlaneBottomC, TRI_GearPlaneBottomD, TRI_GearPlaneBottomE}; if(TagContains(tri.Tag, BottomTagList)){ TVector2 uvi; Rect itembounds = bottombounds; float widthscalex = (1.0f / bbsz.x) * itembounds.width; float widthscaley = (1.0f / bbsz.y) * itembounds.height; uvi = new TVector2((tri.a.Value.x - bmin.x) * widthscalex + itembounds.x, (tri.a.Value.y - bmin.y) * widthscaley + itembounds.y, tri.a.Tag); uvs.Add(uvi); uvi = new TVector2((tri.b.Value.x - bmin.x) * widthscalex + itembounds.x, (tri.b.Value.y - bmin.y) * widthscaley + itembounds.y, tri.b.Tag); uvs.Add(uvi); uvi = new TVector2((tri.c.Value.x - bmin.x) * widthscalex + itembounds.x, (tri.c.Value.y - bmin.y) * widthscaley + itembounds.y, tri.c.Tag); uvs.Add(uvi); } var TopTagList = new string[] {TRI_GearPlaneTopA1, TRI_GearPlaneTopA2, TRI_GearPlaneTopB, TRI_GearPlaneTopC, TRI_GearPlaneTopD, TRI_GearPlaneTopE}; if(TagContains(tri.Tag, TopTagList)){ TVector2 uvi; Rect itembounds = topbounds; float widthscalex = (1.0f / tbsz.x) * itembounds.width; float widthscaley = (1.0f / tbsz.y) * itembounds.height; uvi = new TVector2((tri.a.Value.x - tmin.x) * widthscalex + itembounds.x, (tri.a.Value.y - tmin.y) * widthscaley + itembounds.y, tri.a.Tag); uvs.Add(uvi); uvi = new TVector2((tri.b.Value.x - tmin.x) * widthscalex + itembounds.x, (tri.b.Value.y - tmin.y) * widthscaley + itembounds.y, tri.b.Tag); uvs.Add(uvi); uvi = new TVector2((tri.c.Value.x - tmin.x) * widthscalex + itembounds.x, (tri.c.Value.y - tmin.y) * widthscaley + itembounds.y, tri.c.Tag); uvs.Add(uvi); } //Spoke Layouts var SpokeBottomTagList = new string[] {TRI_SolidSpokePlaneBottom, TRI_SpokeBottom1, TRI_SpokeBottom2}; if(TagContains(tri.Tag, SpokeBottomTagList)){ TVector2 uvi; Rect itembounds = bottomspokebounds; float widthscalex = (1.0f / spokeSz.x) * itembounds.width; float widthscaley = (1.0f / spokeSz.y) * itembounds.height; uvi = new TVector2((tri.a.Value.x - spokeMin.x) * widthscalex + itembounds.x, (tri.a.Value.y - spokeMin.y) * widthscaley + itembounds.y, tri.a.Tag); uvs.Add(uvi); uvi = new TVector2((tri.b.Value.x - spokeMin.x) * widthscalex + itembounds.x, (tri.b.Value.y - spokeMin.y) * widthscaley + itembounds.y, tri.b.Tag); uvs.Add(uvi); uvi = new TVector2((tri.c.Value.x - spokeMin.x) * widthscalex + itembounds.x, (tri.c.Value.y - spokeMin.y) * widthscaley + itembounds.y, tri.c.Tag); uvs.Add(uvi); } var SpokeTopTagList = new string[] {TRI_SolidSpokePlaneTop, TRI_SpokeTop1, TRI_SpokeTop2}; if(TagContains(tri.Tag, SpokeTopTagList)){ TVector2 uvi; Rect itembounds = topspokebounds; float widthscalex = (1.0f / spokeSz.x) * itembounds.width; float widthscaley = (1.0f / spokeSz.y) * itembounds.height; uvi = new TVector2((tri.a.Value.x - spokeMin.x) * widthscalex + itembounds.x, (tri.a.Value.y - spokeMin.y) * widthscaley + itembounds.y, tri.a.Tag); uvs.Add(uvi); uvi = new TVector2((tri.b.Value.x - spokeMin.x) * widthscalex + itembounds.x, (tri.b.Value.y - spokeMin.y) * widthscaley + itembounds.y, tri.b.Tag); uvs.Add(uvi); uvi = new TVector2((tri.c.Value.x - spokeMin.x) * widthscalex + itembounds.x, (tri.c.Value.y - spokeMin.y) * widthscaley + itembounds.y, tri.c.Tag); uvs.Add(uvi); } //Side Spokes... var TopSideSpokeList = new string[] {TRI_SpokeSideTop}; if(TagContains(tri.Tag, TopSideSpokeList)){ Rect itembounds = spokesidebounds; TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; float w = Vector3.Distance(tri.c.Value, tri.b.Value) * vs; float row = Mathf.Floor((w + lastspokesidetopx) / itembounds.width); //float rowCount = Mathf.Ceil((_spokeCount * 2.0f * w) / itembounds.width); float h = Vector3.Distance(tri.a.Value, tri.b.Value) * vs; float adj = itembounds.width - (Mathf.Floor(itembounds.width / w) * w); x = w + lastspokesidetopx - itembounds.width * row + (adj * row); y = itembounds.y + ((h) * row) + (pad * row); uvi1 = new TVector2(x, y, tri.Tag); y = y + h; uvi2 = new TVector2(x, y, tri.Tag); x = lastspokesidetopx - itembounds.width * row + (adj * row); uvi3 = new TVector2(x, y, tri.Tag); lastspokesidetopx +=(w); uvs.Add(uvi1); uvs.Add(uvi2); uvs.Add(uvi3); } var BottomSideSpokeList = new string[] {TRI_SpokeSideBottom}; if(TagContains(tri.Tag, BottomSideSpokeList)){ Rect itembounds = spokesidebounds; TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; float w = Vector3.Distance(tri.a.Value, tri.c.Value) * vs; float row = Mathf.Floor((w + lastspokesidebottomx) / itembounds.width); //float rowCount = Mathf.Ceil((_spokeCount * 2.0f * w) / itembounds.width); float h = Vector3.Distance(tri.b.Value, tri.c.Value) * vs; float adj = itembounds.width - (Mathf.Floor(itembounds.width / w) * w); x = w + lastspokesidebottomx - itembounds.width * row + (adj * row); y = itembounds.y + ((h) * row) + (pad * row); uvi1 = new TVector2(x, y, tri.Tag); x = lastspokesidebottomx - itembounds.width * row + (adj * row); uvi2 = new TVector2(x, y, tri.Tag); y = y + h; uvi3 = new TVector2(x, y, tri.Tag); lastspokesidebottomx +=(w); uvs.Add(uvi1); uvs.Add(uvi3); uvs.Add(uvi2); } //Hub Cap Layouts var HubCapBottomTagList = new string[] {TRI_HubBottom}; if(TagContains(tri.Tag, HubCapBottomTagList)){ TVector2 uvi; Rect itembounds = bottomhubcapbounds; float widthscalex = (1.0f / hubSz.x) * itembounds.width; float widthscaley = (1.0f / hubSz.y) * itembounds.height; uvi = new TVector2((tri.a.Value.x - hubMin.x) * widthscalex + itembounds.x, (tri.a.Value.y - hubMin.y) * widthscaley + itembounds.y, tri.a.Tag); uvs.Add(uvi); uvi = new TVector2((tri.b.Value.x - hubMin.x) * widthscalex + itembounds.x, (tri.b.Value.y - hubMin.y) * widthscaley + itembounds.y, tri.b.Tag); uvs.Add(uvi); uvi = new TVector2((tri.c.Value.x - hubMin.x) * widthscalex + itembounds.x, (tri.c.Value.y - hubMin.y) * widthscaley + itembounds.y, tri.c.Tag); uvs.Add(uvi); } var HubCapTopTagList = new string[] {TRI_HubTop}; if(TagContains(tri.Tag, HubCapTopTagList)){ TVector2 uvi; Rect itembounds = tophubcapbounds; float widthscalex = (1.0f / hubSz.x) * itembounds.width; float widthscaley = (1.0f / hubSz.y) * itembounds.height; uvi = new TVector2((tri.a.Value.x - hubMin.x) * widthscalex + itembounds.x, (tri.a.Value.y - hubMin.y) * widthscaley + itembounds.y, tri.a.Tag); uvs.Add(uvi); uvi = new TVector2((tri.b.Value.x - hubMin.x) * widthscalex + itembounds.x, (tri.b.Value.y - hubMin.y) * widthscaley + itembounds.y, tri.b.Tag); uvs.Add(uvi); uvi = new TVector2((tri.c.Value.x - hubMin.x) * widthscalex + itembounds.x, (tri.c.Value.y - hubMin.y) * widthscaley + itembounds.y, tri.c.Tag); uvs.Add(uvi); } //Tooth Perim 1st Half var OuterListTop = new string[] {TRI_SideOuterTop}; if(TagContains(tri.Tag, OuterListTop)){ TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; Rect itembounds = perimbounds; float w = Vector3.Distance(tri.c.Value, tri.b.Value) * vs * itembounds.width; /// xScale * _topScale; //float h = itembounds.height; // _height / yScale; x = w + lastoutertopx; y = itembounds.y; uvi1 = new TVector2(x, y, tri.Tag); x = lastoutertopx; uvi2 = new TVector2(x, y, tri.Tag); y = itembounds.y + itembounds.height; uvi3 = new TVector2(x, y, tri.Tag); lastoutertopx +=w; uvs.Add(uvi3); uvs.Add(uvi2); uvs.Add(uvi1); } //Tooth Perim 2nd Half var OuterListBottom = new string[] {TRI_SideOuterBottom}; if(TagContains(tri.Tag, OuterListBottom)){ TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; Rect itembounds = perimbounds; float w = Vector3.Distance(tri.a.Value, tri.c.Value) * vs * itembounds.width *_topScale; /// xScale * _topScale; //float h = itembounds.height; // _height / yScale; x = w + lastouterbottomx; y = itembounds.y; uvi1 = new TVector2(x, y, tri.Tag); y = itembounds.y + itembounds.height; uvi2 = new TVector2(x, y, tri.Tag); x = lastouterbottomx; uvi3 = new TVector2(x, y, tri.Tag); lastouterbottomx +=w; uvs.Add(uvi3); uvs.Add(uvi1); uvs.Add(uvi2); } var InnerListTop = new string[] {TRI_SideInnerTop}; if(TagContains(tri.Tag, InnerListTop)){ TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; Rect itembounds = ringbounds; float w = Vector3.Distance(tri.b.Value, tri.c.Value) * vs * itembounds.width; //float h = itembounds.height; x = w + lastinnertopx; y = itembounds.y; uvi1 = new TVector2(x, y, tri.Tag); y = itembounds.y + itembounds.height; uvi2 = new TVector2(x, y, tri.Tag); x = lastinnertopx; uvi3 = new TVector2(x, y, tri.Tag); lastinnertopx +=w; uvs.Add(uvi1); uvs.Add(uvi2); uvs.Add(uvi3); } var InnerListBottom = new string[] {TRI_SideInnerBottom}; if(TagContains(tri.Tag, InnerListBottom)){ TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; Rect itembounds = ringbounds; float w = Vector3.Distance(tri.a.Value, tri.c.Value) * vs * itembounds.width; //float h = _height / yScale; x = lastinnerbottomx; y = itembounds.y; uvi1 = new TVector2(x, y, tri.Tag); x = w + lastinnerbottomx; uvi2 = new TVector2(x, y, tri.Tag); y = itembounds.y + itembounds.height; x = lastinnerbottomx; uvi3 = new TVector2(x, y, tri.Tag); lastinnerbottomx +=w; uvs.Add(uvi2); uvs.Add(uvi3); uvs.Add(uvi1); } var HubListTop = new string[] {TRI_HubSideTop}; if(TagContains(tri.Tag, HubListTop)){ TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; Rect itembounds = hubbounds; float w = Vector3.Distance(tri.c.Value, tri.b.Value) * vs * itembounds.width; //float h = itembounds.height; x = w + lasthubtopx; y = itembounds.y; uvi1 = new TVector2(x, y, tri.Tag); x = lasthubtopx; uvi2 = new TVector2(x, y, tri.Tag); y = itembounds.y + itembounds.height; uvi3 = new TVector2(x, y, tri.Tag); lasthubtopx +=w; uvs.Add(uvi3); uvs.Add(uvi2); uvs.Add(uvi1); } var HubListBottom = new string[] {TRI_HubSideBottom}; if(TagContains(tri.Tag, HubListBottom)){ TVector2 uvi1; TVector2 uvi2; TVector2 uvi3; Rect itembounds = hubbounds; float w = Vector3.Distance(tri.a.Value, tri.c.Value) * vs * itembounds.width; //float h = _hubHeight / yScale; x = w + lasthubbottomx; y = itembounds.y; uvi1 = new TVector2(x, y, tri.Tag); y = itembounds.y + itembounds.height; uvi2 = new TVector2(x, y, tri.Tag); x = lasthubbottomx; uvi3 = new TVector2(x, y, tri.Tag); lasthubbottomx +=w; uvs.Add(uvi3); uvs.Add(uvi1); uvs.Add(uvi2); } } return uvs.ToArray(); }
public ParabolaData(TVector2 focus) { Focus = focus; }
public ResizeWindowEvent(uint width, uint height) : base(GetStaticType()) { this.size = new TVector2 <uint>(width, height); }
public static TVector2 ComputeRayParabolaIntersection( TVector2 rayOrigin, TVector2 rayDirection, TVector2 parabolaFocus, TNumber directrixY) { if (ApproximatelyEqual(0, rayDirection.X)) { var x = rayOrigin.X; TNumber sa, sb, sc; ComputeParabolaStandardForm(parabolaFocus, directrixY, out sa, out sb, out sc); return(new Vector2(x, sa * x * x + sb * x + sc)); } if (MathUtil.ApproximatelyEqual(directrixY, parabolaFocus.Y)) { directrixY += 0.2f; } // Given an intersecting ray R and parabola P, find the first point of intersection. // // Let ro be the ray origin point (rox, roy) // rd be the ray direction vector (rdx, rdy) // pf be the parabola focus point (pfx, pfy) // dy be the directrix y-coordinate // // Let t be the ray parameterization variable in [0, inf) // s be the solution point (sx, sy), s = ro + rd * t // // By definition of parabola: // dy - sy = |s - f| // (dy - sy)^2 = |s - f|^2 // // Expand (dy - sy)^2: // (dy - sy)^2 // (dy - (roy + rdy * t))^2 // ((dy - roy) - rdy * t)^2 // (dy - roy)^2 - 2 (dy - roy) (rdy * t) + (rdy * t)^2 // (dy - roy)^2 - 2 (dy - roy) (rdy) t + (rdy^2) t^2 // // Expand |s - f|^2: // (sx - fx)^2 + (sy - fy)^2 // ((rox + rdx * t) - fx)^2 + ((roy + rdy * t) - fy)^2 // // Expand ((rox + rdx * t) - fx)^2: // ((rdx * t) + (rox - fx))^2 // (rdx * t)^2 + 2 (rdx * t) (rox - fx) + (rox - fx)^2 // (rdx^2) t^2 + t (2 rdx (rox - fx)) + (rox - fx)^2 // // Expand ((roy + rdy * t) - fy)^2: (likewise) // (rdy^2) t^2 + t (2 rdy (roy - fy)) + (roy - fy)^2 // // (rdx^2) t^2 + t (2 rdx (rox - fx)) + (rox - fx)^2 + (rdy^2) t^2 + t (2 rdy (roy - fy)) + (roy - fy)^2 // (rdx^2 + rdy^2) t^2 + t (2 rdx (rox - fx) + 2 rdy (roy - fy)) + (rox - fx)^2 + (roy - fy)^2 // // Back to: dy - sy = |s - f| // (dy - sy)^2 = |s - f|^2 // // (dy - roy)^2 - 2 (dy - roy) (rdy) t + (rdy^2) t^2 = // (rdx^2 + rdy^2) t^2 + t (2 rdx (rox - fx) + 2 rdy (roy - fy)) + (rox - fx)^2 + (roy - fy)^2 // // 0 = t^2 (rdx^2 + rdy^2 - rdy^2) + // t (2 rdx (rox - fx) + 2 rdy (roy - fy) + 2 (dy - roy) (rdy)) + // 1 ((rox - fx)^2 + (roy - fy)^2 - (dy - roy)^2) // // 0 = t^2 (rdx^2) + // t (2 rdx rox - 2 rdx fx + 2 rdy roy - 2 rdy fy + 2 rdy dy - 2 rdy roy) + // 1 (rox^2 - 2 rox fx + fx^2 + roy^2 - 2 roy fy + fy^2 - dy^2 + 2 dy roy - roy^2) // // 0 = t^2 (rdx^2) + // t (2 rdx rox - 2 rdx fx - 2 rdy fy + 2 rdy dy) + // 1 (rox^2 - 2 rox fx + fx^2 - 2 roy fy + fy^2 - dy^2 + 2 dy roy) var roxMinusFx = rayOrigin.X - parabolaFocus.X; var royMinusFy = rayOrigin.Y - parabolaFocus.Y; var dyMinusRoy = directrixY - rayOrigin.Y; var a = rayDirection.X * rayDirection.X; var b = 2 * (rayDirection.X * roxMinusFx - rayDirection.Y * (parabolaFocus.Y - directrixY)); var c = roxMinusFx * roxMinusFx + royMinusFy * royMinusFy - dyMinusRoy * dyMinusRoy; TNumber pickedT = default(TNumber); if (!MathUtil.ApproximatelyEqual(0, a)) { var centerT = -b / (2 * a); var offsetT = (TNumber)Math.Sqrt(b * b - 4 * a * c) / (2 * a); var lowerT = centerT - offsetT; var upperT = centerT + offsetT; pickedT = lowerT >= 0 ? lowerT : upperT; } if (TNumber.IsNaN(pickedT)) { // Debugger.Break(); pickedT = 0; } return(rayOrigin + pickedT * rayDirection); }
public DType Accept(TVector2 type, IEnumerable <ExcelStream> x, bool y, DefAssembly ass) { throw new NotImplementedException(); }
public static TVector2 ComputeRayPointAtY(TVector2 rayOrigin, TVector2 rayDirection, TNumber y) { var dy = y - rayOrigin.Y; return(rayOrigin + (rayDirection * dy) / rayDirection.Y); }
public string Accept(TVector2 type, string jsonVarName, string fieldName) { return($"{fieldName} = Vector2.fromJson({jsonVarName});"); }
public static TVector2 ComputeParabolaPointGivenX(TNumber rx, TNumber directrixY, TVector2 focus) { // Let result be a point r (rx, ry) located between the focus's y and directrix y. // directrixY - ry = sqrt((rx - focusX)^2 + (ry - focusY)^2) // (directrixY - ry)^2 = (rx - focusX)^2 + (ry - focusY)^2 // directrixY^2 - 2 directrixY ry + ry^2 = rx^2 - 2 rx focusX + focusX^2 + ry^2 - 2 ry focusY + focusY^2 // -2 directrixY ry + ry^2 = rx^2 - 2 rx focusX + focusX^2 + ry^2 - 2 ry focusY + focusY^2 - directrixY^2 // -2 directrixY ry + ry^2 - ry^2 + 2 ry focusY = rx^2 - 2 rx focusX + focusX^2 + focusY^2 - directrixY^2 // -2 directrixY ry + 2 ry focusY = rx^2 - 2 rx focusX + focusX^2 + focusY^2 - directrixY^2 // ry (-2 directrixY + 2 focusY) = rx^2 - 2 rx focusX + focusX^2 + focusY^2 - directrixY^2 // ry = (rx^2 - 2 rx focusX + focusX^2 + focusY^2 - directrixY^2) / (-2 directrixY + 2 focusY) var numerator = rx * rx - 2 * rx * focus.X + focus.X * focus.X + focus.Y * focus.Y - directrixY * directrixY; var denominator = -2 * directrixY + 2 * focus.Y; var ry = numerator / denominator; return(new TVector2(rx, ry)); }
public virtual TR Accept(TVector2 type) { return DoAccept(type); }
void ProcessCircleEvent(FortunesAlgorithmState state, CircleEvent e) { var sweepY = e.Y; var swallowedParabolaNode = e.SwallowedParabolaNode; if (swallowedParabolaNode.Parent == null) { return; } Node leftAncestor, rightAncestor; swallowedParabolaNode.FindDirectionalAncestors(out leftAncestor, out rightAncestor); var leftAncestorEdgeRayData = (EdgeRayData)leftAncestor.Data; var rightAncestorEdgeRayData = (EdgeRayData)rightAncestor.Data; state.VoronoiEdges.Add(new VoronoiEdge( leftAncestorEdgeRayData.Origin, leftAncestorEdgeRayData.IsOriginBounded, e.Circumcenter, true)); state.VoronoiEdges.Add(new VoronoiEdge( rightAncestorEdgeRayData.Origin, leftAncestorEdgeRayData.IsOriginBounded, e.Circumcenter, true)); var leftParabolaNode = leftAncestor.Left.GetRightmost(); var leftParabolaFocus = ((ParabolaData)leftParabolaNode.Data).Focus; var rightParabolaNode = rightAncestor.Right.GetLeftmost(); var rightParabolaFocus = ((ParabolaData)rightParabolaNode.Data).Focus; state.DelanayEdges.Add(new VoronoiEdge(leftParabolaFocus, true, rightParabolaFocus, true)); // One ancestor will become the edge shared by the left/right parabolas, // the other will be deleted. It's guranteed our parent is one of these // ancestors and that the other ancestor is above it (that is, it has a // parent) so opt to delete our parent. var nodeParent = swallowedParabolaNode.Parent; var nodeSibling = nodeParent.Left == swallowedParabolaNode ? nodeParent.Right : nodeParent.Left; NodeOperations.ReplaceNode(nodeParent, nodeSibling, ref state.Root); nodeParent.Left = nodeParent.Right = null; var olderAncestor = nodeParent == leftAncestor ? rightAncestor : leftAncestor; var leftFocusRightFocus = rightParabolaFocus - leftParabolaFocus; // x is positive var edgeDirection = new TVector2(-leftFocusRightFocus.Y, leftFocusRightFocus.X); var leftRightFocusCenter = new TVector2( MathUtil.Average(leftParabolaFocus.X, rightParabolaFocus.X), MathUtil.Average(leftParabolaFocus.Y, rightParabolaFocus.Y)); var dy = sweepY - leftRightFocusCenter.Y; var edgeStart = e.Circumcenter; olderAncestor.Data = new EdgeRayData(true, edgeStart, edgeDirection); // add new potential circle events Node leftLeftLeaf; if (leftParabolaNode.TryGetLeftLeaf(out leftLeftLeaf)) { HandleAddCircleEvent(state, leftLeftLeaf, leftParabolaNode, rightParabolaNode, sweepY); } Node rightRightLeaf; if (rightParabolaNode.TryGetRightLeaf(out rightRightLeaf)) { HandleAddCircleEvent(state, leftParabolaNode, rightParabolaNode, rightRightLeaf, sweepY); } }
private void DrawPointX(Graphics g, TVector2 point, int dims, Pen pen = null) { g.DrawLine(pen ?? Pens.Black, point.X - dims, point.Y - dims, point.X + dims, point.Y + dims); g.DrawLine(pen ?? Pens.Black, point.X + dims, point.Y - dims, point.X - dims, point.Y + dims); }
public SiteEvent(TVector2 point) { Point = point; }
public string Accept(TVector2 type, string bufName, string fieldName) { return($"{bufName}.WriteVector2({fieldName});"); }
public void Accept(TVector2 type, Dictionary <string, DefTypeBase> x) { }