internal double DistanceAlongRay2(DmtxRay2 ray) { if (Math.Abs(1.0 - ray.V.Mag()) > DmtxConstants.DmtxAlmostZero) { throw new ArgumentException("DistanceAlongRay2: The ray's V vector must be a unit vector"); } return((this - ray.P).Dot(ray.V)); }
internal bool PointAlongRay2(DmtxRay2 ray, double t) { if (Math.Abs(1.0 - ray.V.Mag()) > DmtxConstants.DmtxAlmostZero) { throw new ArgumentException("PointAlongRay: The ray's V vector must be a unit vector"); } DmtxVector2 tmp = new DmtxVector2(ray.V._x * t, ray.V._y * t); this._x = ray.P._x + tmp._x; this._y = ray.P._y + tmp._y; return(true); }
internal bool Intersect(DmtxRay2 p0, DmtxRay2 p1) { double denominator = p1.V.Cross(p0.V); if (Math.Abs(denominator) < DmtxConstants.DmtxAlmostZero) { return(false); } double numerator = p1.V.Cross(p1.P - p0.P); return(PointAlongRay2(p0, numerator / denominator)); }
bool RegionUpdateXfrms(DmtxRegion reg) { double radians; DmtxRay2 rLeft = new DmtxRay2(); DmtxRay2 rBottom = new DmtxRay2(); DmtxRay2 rTop = new DmtxRay2(); DmtxRay2 rRight = new DmtxRay2(); DmtxVector2 p00 = new DmtxVector2(); DmtxVector2 p10 = new DmtxVector2(); DmtxVector2 p11 = new DmtxVector2(); DmtxVector2 p01 = new DmtxVector2(); if (!(reg.LeftKnown != 0 && reg.BottomKnown != 0)) { throw new ArgumentException("Error updating Xfrms!"); } /* Build ray representing left edge */ rLeft.P.X = (double)reg.LeftLoc.X; rLeft.P.Y = (double)reg.LeftLoc.Y; radians = reg.LeftAngle * (Math.PI / DmtxConstants.DmtxHoughRes); rLeft.V.X = Math.Cos(radians); rLeft.V.Y = Math.Sin(radians); rLeft.TMin = 0.0; rLeft.TMax = rLeft.V.Norm(); /* Build ray representing bottom edge */ rBottom.P.X = (double)reg.BottomLoc.X; rBottom.P.Y = (double)reg.BottomLoc.Y; radians = reg.BottomAngle * (Math.PI / DmtxConstants.DmtxHoughRes); rBottom.V.X = Math.Cos(radians); rBottom.V.Y = Math.Sin(radians); rBottom.TMin = 0.0; rBottom.TMax = rBottom.V.Norm(); /* Build ray representing top edge */ if (reg.TopKnown != 0) { rTop.P.X = (double)reg.TopLoc.X; rTop.P.Y = (double)reg.TopLoc.Y; radians = reg.TopAngle * (Math.PI / DmtxConstants.DmtxHoughRes); rTop.V.X = Math.Cos(radians); rTop.V.Y = Math.Sin(radians); rTop.TMin = 0.0; rTop.TMax = rTop.V.Norm(); } else { rTop.P.X = (double)reg.LocT.X; rTop.P.Y = (double)reg.LocT.Y; radians = reg.BottomAngle * (Math.PI / DmtxConstants.DmtxHoughRes); rTop.V.X = Math.Cos(radians); rTop.V.Y = Math.Sin(radians); rTop.TMin = 0.0; rTop.TMax = rBottom.TMax; } /* Build ray representing right edge */ if (reg.RightKnown != 0) { rRight.P.X = (double)reg.RightLoc.X; rRight.P.Y = (double)reg.RightLoc.Y; radians = reg.RightAngle * (Math.PI / DmtxConstants.DmtxHoughRes); rRight.V.X = Math.Cos(radians); rRight.V.Y = Math.Sin(radians); rRight.TMin = 0.0; rRight.TMax = rRight.V.Norm(); } else { rRight.P.X = (double)reg.LocR.X; rRight.P.Y = (double)reg.LocR.Y; radians = reg.LeftAngle * (Math.PI / DmtxConstants.DmtxHoughRes); rRight.V.X = Math.Cos(radians); rRight.V.Y = Math.Sin(radians); rRight.TMin = 0.0; rRight.TMax = rLeft.TMax; } /* Calculate 4 corners, real or imagined */ if (!p00.Intersect(rLeft, rBottom)) return false; if (!p10.Intersect(rBottom, rRight)) return false; if (!p11.Intersect(rRight, rTop)) return false; if (!p01.Intersect(rTop, rLeft)) return false; if (!RegionUpdateCorners(reg, p00, p10, p11, p01)) return false; return true; }
internal double DistanceFromRay2(DmtxRay2 ray) { if (Math.Abs(1.0 - ray.V.Mag()) > DmtxConstants.DmtxAlmostZero) { throw new ArgumentException("DistanceFromRay2: The ray's V vector must be a unit vector"); } return ray.V.Cross(this - ray.P); }
internal bool PointAlongRay2(DmtxRay2 ray, double t) { if (Math.Abs(1.0 - ray.V.Mag()) > DmtxConstants.DmtxAlmostZero) { throw new ArgumentException("PointAlongRay: The ray's V vector must be a unit vector"); } DmtxVector2 tmp = new DmtxVector2(ray.V._x * t, ray.V._y * t); this._x = ray.P._x + tmp._x; this._y = ray.P._y + tmp._y; return true; }
internal bool Intersect(DmtxRay2 p0, DmtxRay2 p1) { double denominator = p1.V.Cross(p0.V); if (Math.Abs(denominator) < DmtxConstants.DmtxAlmostZero) { return false; } double numerator = p1.V.Cross(p1.P - p0.P); return PointAlongRay2(p0, numerator / denominator); }