/*** Distance between two points***/ public double DistanceTo(CPoint2D point) { return(Math.Sqrt((point.X - this.X) * (point.X - this.X) + (point.Y - this.Y) * (point.Y - this.Y))); }
/************************************************ * Offset the line segment to generate a new line segment * If the offset direction is along the x-axis or y-axis, * Parameter is true, other wise it is false * ***********************************************/ public CLineSegment OffsetLine(double distance, bool rightOrDown) { //offset a line with a given distance, generate a new line //rightOrDown=true means offset to x incress direction, // if the line is horizontal, offset to y incress direction CLineSegment line; CPoint2D newStartPoint = new CPoint2D(); CPoint2D newEndPoint = new CPoint2D(); double alphaInRad = this.GetLineAngle(); // 0-PI if (rightOrDown) { if (this.HorizontalLine()) //offset to y+ direction { newStartPoint.X = this.m_startPoint.X; newStartPoint.Y = this.m_startPoint.Y + distance; newEndPoint.X = this.m_endPoint.X; newEndPoint.Y = this.m_endPoint.Y + distance; line = new CLineSegment(newStartPoint, newEndPoint); } else //offset to x+ direction { if (Math.Sin(alphaInRad) > 0) { newStartPoint.X = m_startPoint.X + Math.Abs(distance * Math.Sin(alphaInRad)); newStartPoint.Y = m_startPoint.Y - Math.Abs(distance * Math.Cos(alphaInRad)); newEndPoint.X = m_endPoint.X + Math.Abs(distance * Math.Sin(alphaInRad)); newEndPoint.Y = m_endPoint.Y - Math.Abs(distance * Math.Cos(alphaInRad)); line = new CLineSegment( newStartPoint, newEndPoint); } else //sin(FalphaInRad)<0 { newStartPoint.X = m_startPoint.X + Math.Abs(distance * Math.Sin(alphaInRad)); newStartPoint.Y = m_startPoint.Y + Math.Abs(distance * Math.Cos(alphaInRad)); newEndPoint.X = m_endPoint.X + Math.Abs(distance * Math.Sin(alphaInRad)); newEndPoint.Y = m_endPoint.Y + Math.Abs(distance * Math.Cos(alphaInRad)); line = new CLineSegment( newStartPoint, newEndPoint); } } } //{rightOrDown} else //leftOrUp { if (this.HorizontalLine()) //offset to y directin { newStartPoint.X = m_startPoint.X; newStartPoint.Y = m_startPoint.Y - distance; newEndPoint.X = m_endPoint.X; newEndPoint.Y = m_endPoint.Y - distance; line = new CLineSegment( newStartPoint, newEndPoint); } else //offset to x directin { if (Math.Sin(alphaInRad) >= 0) { newStartPoint.X = m_startPoint.X - Math.Abs(distance * Math.Sin(alphaInRad)); newStartPoint.Y = m_startPoint.Y + Math.Abs(distance * Math.Cos(alphaInRad)); newEndPoint.X = m_endPoint.X - Math.Abs(distance * Math.Sin(alphaInRad)); newEndPoint.Y = m_endPoint.Y + Math.Abs(distance * Math.Cos(alphaInRad)); line = new CLineSegment( newStartPoint, newEndPoint); } else //sin(FalphaInRad)<0 { newStartPoint.X = m_startPoint.X - Math.Abs(distance * Math.Sin(alphaInRad)); newStartPoint.Y = m_startPoint.Y - Math.Abs(distance * Math.Cos(alphaInRad)); newEndPoint.X = m_endPoint.X - Math.Abs(distance * Math.Sin(alphaInRad)); newEndPoint.Y = m_endPoint.Y - Math.Abs(distance * Math.Cos(alphaInRad)); line = new CLineSegment( newStartPoint, newEndPoint); } } } return(line); }
public CLine(Double angleInRad, CPoint2D point) { Initialize(angleInRad, point); }
public CLineSegment(CPoint2D startPoint, CPoint2D endPoint) : base(startPoint, endPoint) { this.m_startPoint = startPoint; this.m_endPoint = endPoint; }