/// <summary> /// overrides the <see cref="PlaneSurface.Normal(double, double)"/> method. /// </summary> /// <param name="u">first parameter.</param> /// <param name="v">second parameter.</param> /// <returns>the normal vector.</returns> public override xyz Normal(double u, double v) { xy value = new xy(u, v); double dir = 1; if (!SameSense) { dir = -1; } u = value.x; v = value.y; if (!Smooth) { return(base.Normal(u, v)); } if (value.dist(A11) < 0.001) { return(N11.normalized() * dir); } if (value.dist(A01) < 0.001) { return(N01.normalized() * dir); } if (value.dist(A10) < 0.001) { return(N10.normalized() * dir); } if (value.dist(A00) < 0.001) { return(N00.normalized() * dir); } if (A10.dist(A01) < 0.00001) { xyz B = BaryCentric(A00, A10, A11, value); return(((N00)*B.x + (N10)*B.y + (N11)*B.z) * dir); } if (((A10 - value) & (A01 - value)) == 0) { } if (((A00 - value) & (A01 - value)) > 0) { xyz B = BaryCentric(A11, A00, A01, value); return(((N11)*B.x + (N00)*B.y + (N01)*B.z) * dir); } else { xyz B = BaryCentric(A00, A11, A10, value); return(((N00)*B.x + (N11)*B.y + (N10)*B.z) * dir); } }
/// <summary> /// overrides the <see cref="CtrlEntity.OnMouseUp(HandledMouseEventArgs)"/> method. /// </summary> /// <param name="e"></param> /// <returns></returns> public override void OnMouseUp(HandledMouseEventArgs e) { if (escaped) { escaped = false; { e.Handled = true; return; } } if (A.dist(B) < 20) { e.Handled = true; return; } RectangleF R = Utils.ToRectangle(A, B); double Factor = (float)Device.WinControl.ClientSize.Width / R.Width; Device.Camera.ZoomTransform(new Point((int)(R.X + R.Width / 2), (int)(R.Y + R.Height / 2)), new Point((int)Device.ViewPort.Width / 2, (int)Device.ViewPort.Height / 2), Factor); Device.Selector.RefreshSnapBuffer(); CurrentState = State.FirstPoint; A = B; Device.ForegroundDrawEnable = false; Device.OutFitChanged = true; Device = null; base.OnMouseUp(e); return; }
/// <summary> /// This method calculates the distance to a point only, if the distance is /// smaller then MaxDist, otherwise Utils.big will be returned. /// You can imagine a strip with width MaxDist along the line. /// If a point is placed on this /// strip, it is accepted and the distance will be calculated and returned. /// If CheckP is true, additional to the strip a half circle with center P and radius Maxdist is /// considered and analogusly for CheckQ. /// </summary> /// <param name="p">The point to be tested</param> /// <param name="MaxDist">The maximal distance, for which a reasonable result can be provided.</param> /// <param name="CheckP">If CheckP is true: If the distance between p and <b>this.P</b> is less than MaxDist, it will be provided as a result. The value of Lam is zero.</param> /// <param name="CheckQ">If CheckQ is true: If the distance between p and <b>this.Q</b> is less than MaxDist, it will be provided as a result. The value of Lam is one. </param> /// <param name="Lam">The param Lam can be used to calculate the nearest point on the line by Value(Lam)</param> /// <returns>In case the distance of the line is smaller then Maxdist, the distance is returned else <see cref="Utils.big"/> /// </returns> public double Distance(xy p, double MaxDist, bool CheckP, bool CheckQ, out double Lam) { double dil = Utils.big; double dia = Utils.big; double dib = Utils.big; double result = Utils.big; xy Nearest; Lam = -1; double di = Distance(p, out Lam, out Nearest); if (!Utils.Less(MaxDist, di) && !Utils.Less(Lam, 0) && !Utils.Less(1, Lam)) { dil = di; } if (CheckP) { dia = p.dist(P); } if (CheckQ) { dib = p.dist(Q); } if (!Utils.Less(MaxDist, dia) && !Utils.Less(dil, dia) && !Utils.Less(dib, dia)) { Lam = 0; result = dia; } else if (!Utils.Less(MaxDist, dib) && !Utils.Less(dil, dib) && !Utils.Less(dia, dib)) { Lam = 1; result = dib; } else if (!Utils.Less(MaxDist, dil) && Utils.Less(dil, dia) && Utils.Less(dil, dib)) { result = dil; } return(result); }
static bool TwoLines(xy A1, xy B1, xy A2, xy B2, ref double Lam, ref double Mue) { if (A1.dist(B1) < 0.0000001) { return(false); } if (A2.dist(B2) < 0.0000001) { return(false); } if ((A2.dist(B1) < Tolerance)) { Lam = 1 - LuckyEpsilon; Mue = 0; return(true); } if ((A1.dist(B2) < Tolerance)) { Mue = 1 - LuckyEpsilon; Lam = 0; return(true); } Lam = -1; Mue = -1; xy Direction1 = B1 - A1; xy Direction2 = B2 - A2; double d = Direction1 & Direction2; if (!(System.Math.Abs(d) < 0.000000001)) { Mue = System.Math.Round((Direction1 & (B1 - A2)) / d, 9); Lam = System.Math.Round((Direction2 & (A1 - B2)) / d, 9); return(true); } return(false); }
/// <summary> /// overrides the <see cref="ProjectPoint(xyz)"/> method of <see cref="Surface"/>. /// </summary> /// <param name="Point">Point, wich will be projected th the surface</param> /// <returns>u amd v parameter. A call <b>Point</b></returns> public override xy ProjectPoint(xyz Point) { xyz p = Base.Relativ(Point); xyz PD = new xyz(0, 0, 0); xyz PU = new xyz(0, 0, 0); double Lam = -1; double Param = -1; DownPlane.Cross(new LineType(p, Direction), out Lam, out PD); UpPlane.Cross(new LineType(p, Direction), out Lam, out PU); xyzArray A = CurveArray; xyz R = StandardBase.Relativ(p); double u = Curve.Arcus(new xy(R.X, R.y)); xy PP11 = Curve.Value(u); if (PP11.dist(new xy(R.X, R.Y)) > 0.5) { } else { } A.Distance(new LineType(p, Direction), 1e10, out Param, out Lam); if (Height < 0) { double v = p.dist(PD) / PU.dist(PD); xyz PP = Value(u, v); return(new xy(u, v)); } else { xy pt = Curve.Value(u); xyz K = StandardBase.BaseX * pt.x + StandardBase.BaseY * pt.y; Plane P = new Plane(Base.BaseO, Base.BaseZ); LineType L = new LineType(K, Direction); xyz pkt = new xyz(0, 0, 0); P.Cross(L, out Lam, out pkt); double v = pkt.dist(p) / Height; xyz PP1 = Value(u, v); return(new xy(u, v)); } }
static int Prev(int i) { xy V1 = new xy(0, 0); int result = i - 1; do { if (result < 0) { result = _Array1.Count - 2; } V1 = _Array1[result] - _Array1[i]; if (V1.length() < 0.001) { result--; } } while (V1.dist(xy.Null) < 0.000001); return(result); }
/// <summary> /// This method calculates the distance to a point Pt <seealso cref="Distance(xy , out double, out xy)"/>. /// The difference to <see cref="Distance(xy , out double, out xy)"/> is:<br/> /// If the normalprojection from the Point Pt is outside of PQ then the distance to the /// Point P resp Q is taken and Lam is 0 resp 1. /// The parameter Lam can be taken to calculate the nearest point of the LineType, which is /// also returned by the outvalue Nearest /// </summary> /// <param name="Pt">Point to calculate the distance to the LineType</param> /// <param name="Lam">Parameter to calculate the nearest point</param> /// <returns>Returns the distance from the line to the point Pt</returns> public double DistanceBounded(xy Pt, out double Lam) { xy Dummy = new xy(0, 0); double Result = Distance(Pt, out Lam, out Dummy); if ((!Utils.Less(Lam, 0)) && ((!Utils.Less(1, Lam)))) { return(Result); } double DiP = P.dist(Pt); double DiQ = Q.dist(Pt); if (DiP < DiQ) { Result = DiP; Lam = 0; return(Result); } Result = DiQ; Lam = 1; return(Result); }
/// <summary> /// This method calculates the distance to a point Pt. /// The parameter Lam can be taken to calculate the nearest point of the LineType, which is /// also returned by the outvalue Nearest /// </summary> /// <param name="Pt">Point to calculate the distance to the LineType</param> /// <param name="Lam">Parameter to calculate the nearest point</param> /// <param name="Nearest">The point on the line which has the smallest distance to Pt</param> /// <returns>Returns the distance from the line to the point Pt</returns> public double Distance(xy Pt, out double Lam, out xy Nearest) { Lam = Direction.normalize() * (Pt - P) / Direction.length(); Nearest = P + Direction * Lam; return(Nearest.dist(Pt)); }
/// <summary> /// overrides the draw nethod and paints the axis. /// </summary> /// <param name="Device"></param> protected override void OnDraw(OpenGlDevice Device) { if (FullSize) { xy WE = Device.WorldExtensions; if (WE.dist(Size.toXY()) > 0.2) { SetInvalid(true); } Size = new xyz(WE.x, WE.y, WE.x); } if (Font == null) { Font = new Drawing3d.Font(FontName); } SaveFontSize = Font.FontSize; Font.FontSize = TextHeight; base.OnDraw(Device); Device.PushMatrix(); Device.MulMatrix(AxesBase.ToMatrix()); bool SaveLighting = Device.LightEnabled; Device.LightEnabled = false; Color Save = Device.Emission; Device.Emission = Color; if (LeftAndRight) { Device.drawLine(new xyz(-Size.x, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, -Size.y, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, -Size.z), new xyz(0, 0, Size.z)); } } { Device.drawLine(new xyz(0, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, 0, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, 0), new xyz(0, 0, Size.z)); } } xyz n1 = new xyz(0, DeviderLineLength, 0); int from = (int)(-Size.x / Devider.x); if (!LeftAndRight) { from = 0; } if (Device.RenderKind == RenderKind.Render) { for (int i = from; i <= Size.x / Devider.x; i++) { if (ShowDevider) { Device.drawLine(new xyz(Devider.x * i, 0, 0) - n1, new xyz(Devider.x * i, 0, 0) + n1); } if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).x / 2f); Device.drawText(Font, Matrix.Translation(new xyz(Pos, DeviderLineLength, 0)), i.ToString(), 0); } } from = (int)(-Size.y / Devider.y); if (!LeftAndRight) { from = 0; } n1 = new xyz(DeviderLineLength, 0, 0); for (int i = from; i <= Size.y / Devider.y; i++) { if (i != 0) { if (ShowDevider) { Device.drawLine(new xyz(0, Devider.y * i, 0) - n1, new xyz(0, Devider.y * i, 0) + n1); } if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, Pos, 0)), i.ToString(), 0); } } } if (Dim3d) { for (int i = from; i <= Size.z / Devider.z; i++) { if (i != 0) { if (ShowDevider) { Device.drawLine(new xyz(0, 0, Devider.z * i) - n1, new xyz(0, 0, Devider.z * i) + n1); } if (ShowText) { double Pos = Devider.z * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, 0, Pos)), i.ToString(), 0); } } } } } if (Device.RenderKind == RenderKind.SnapBuffer) { if (LeftAndRight) { Device.drawLine(new xyz(-Size.x, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, -Size.y, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, -Size.z), new xyz(0, 0, Size.z)); } } else if (LeftAndRight) { Device.drawLine(new xyz(0, 0, 0), new xyz(Size.x, 0, 0)); Device.drawLine(new xyz(0, 0, 0), new xyz(0, Size.y, 0)); if (Dim3d) { Device.drawLine(new xyz(0, 0, 0), new xyz(0, 0, Size.z)); } } for (int i = from; i <= Size.x / Devider.x; i++) { Device.drawPoint(new xyz(Devider.x * i, 0, 0), Devider.x / 4); if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).x / 2f); MeshContainer M = MeshCreator.MeshListCurrent; Device.drawText(Font, Matrix.Translation(new xyz(Pos, DeviderLineLength, 0)), i.ToString(), 0); M = MeshCreator.MeshListCurrent; } } from = (int)(-Size.y / Devider.y); if (!LeftAndRight) { from = 0; } n1 = new xyz(DeviderLineLength, 0, 0); for (int i = from; i <= Size.y / Devider.y; i++) { if (i != 0) { Device.drawPoint(new xyz(0, Devider.y * i, 0), Devider.x / 4); if (ShowText) { double Pos = Devider.x * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, Pos, 0)), i.ToString(), 0); } } } if (Dim3d) { for (int i = from; i <= Size.z / Devider.z; i++) { if (i != 0) { Device.drawPoint(new xyz(0, 0, Devider.z * i), Devider.x / 4); if (ShowText) { double Pos = Devider.z * i - ((float)Device.getEnvText(Font, i.ToString()).y / 2f); Device.drawText(Font, Matrix.Translation(new xyz(DeviderLineLength, 0, Pos)), i.ToString(), 0); } } } } } Device.Emission = Save; Device.LightEnabled = SaveLighting; Font.FontSize = SaveFontSize; Device.PopMatrix(); }