Forum > Graphics
GraphMath unit / LineEndPoint
BubikolRamios:
Is this expected, or ?
--- Quote ---{------------------------------------------------------------------------------
Method: LineEndPoint
Params: StartPoint, Angle, Length
Returns: TPoint
Use LineEndPoint to get the End-Point of a line of ANY given Length at
any given angle with any given Start-Point. It is primarily for use in
other routines such as RadialPoint. The angle is in 1/16th of a degree.
For example, a full circle equals 5760 (16*360). Zero degrees is at the
3'o clock position.
------------------------------------------------------------------------------}
--- End quote ---
1.Test LineEndPoint.
See image 1
From center, find end point at 0 degrees, and 100 distance. Find end points from there under +/-90 angle,distance 100, connect, --> draw tangent.
2. let me see tangent for all 360 degrees, step 10
see image 2
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// some not needed declarations, delete them var arr: TFloatPointArray; t,t1,t2: TfloatPoint; str:string; toCanvasCenterX,toCanvasCenterY: integer; alpha: integer;begin //arr := getLineEndPointsMC(FloatPoint(0,0),degtorad(0),200); str := ''; toCanvasCenterX := round(PaintBox1.width/2); toCanvasCenterY := round(PaintBox1.Height/2); PaintBox1.Canvas.Brush.Color := clWhite; PaintBox1.Canvas.EllipseC(0+ toCanvasCenterX,toCanvasCenterY - 0,100,100); alpha := 0; while alpha < 360 do begin t := LineEndPoint(FloatPoint(0,0),alpha*16,100); PaintBox1.Canvas.Pen.Color := clBlack; PaintBox1.Canvas.Line(round(FloatPoint(0,0).x+ toCanvasCenterX),round(toCanvasCenterY -FloatPoint(0,0).Y),round(t.x+ toCanvasCenterX),round(toCanvasCenterY -t.y)); PaintBox1.Canvas.Pen.Color := clRed; PaintBox1.Canvas.Ellipse(Rect(Round(t.X-2+ toCanvasCenterX), Round(toCanvasCenterY - t.Y-2), Round(t.X+2+ toCanvasCenterX), Round(toCanvasCenterY - t.Y+2))); t1 := LineEndPoint(t,(alpha+90)*16,100); PaintBox1.Canvas.Pen.Color := clBlue; PaintBox1.Canvas.Ellipse(Rect(Round(t1.X-2+ toCanvasCenterX), Round(toCanvasCenterY - t1.Y-2), Round(t1.X+2+ toCanvasCenterX), Round(toCanvasCenterY - t1.Y+2))); t2 := LineEndPoint(t,(alpha-90)*16,100); PaintBox1.Canvas.Pen.Color := clBlue; PaintBox1.Canvas.Ellipse(Rect(Round(t2.X-2+ toCanvasCenterX), Round(toCanvasCenterY - t2.Y-2), Round(t2.X+2+ toCanvasCenterX), Round(toCanvasCenterY - t2.Y+2))); PaintBox1.Canvas.Line(round(t1.x+ toCanvasCenterX),round(toCanvasCenterY -t1.Y),round(t2.x+ toCanvasCenterX),round(toCanvasCenterY -t2.y)); alpha := alpha +10; end;end;
tetrastes:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- //t1 := LineEndPoint(t,(alpha+90)*16,100); a2 := alpha + 90; if a2 > 359 then a2 := a2 - 360; t1 := LineEndPoint(t,a2*16,100);
BubikolRamios:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- if a2 > 359 then a2 := a2 - 360;probably this should be handled inside LineEndPoint, right ?
extracted, and all I did removed '16', and now returns FloatPoint insead of Point
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var sinAngle, cosAngle: Extended;begin if angleDegrees > 360 then angleDegrees := Frac(angleDegrees / 360) * 360; if angleDegrees < 0 then angleDegrees := 360 - abs(angleDegrees); SinCos(DegToRad(angleDegrees), sinAngle, cosAngle); Result.Y := StartPoint.Y - Round(Length*sinAngle); Result.X := StartPoint.X + Round(Length*cosAngle);end;
and all works OK, one can do
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---while alpha < num greater than 360 do
and it works.
tetrastes:
Yes, you are right. There is error in graphmath.pp:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- if Angle > 360*16 then Angle := Frac(Angle / 360*16) * 360*16;
must be
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- if Angle > 360*16 then Angle := Frac(Angle / (360*16)) * 360*16;
BubikolRamios:
Have no clue where to file bug report ... I hope you will do it.
Navigation
[0] Message Index
[#] Next page