Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Drawing of the arrowhead on the end of drown Line. |
Post Reply |
Author | |
Michael_67
Beginner Joined: 07 Aug 15 Location: DE Status: Offline Points: 10 |
Post Options
Thanks(0)
Posted: 07 Aug 15 at 8:54AM |
Hello.
What's the easiest way, to draw an arrowhead (two short lines or a triangle does not matter) at the end of with DrawLine(double StartX, double StartY, double EndX, double EndY) drawn line? A snippet, best in C #, would be nice. |
|
mLipok
Senior Member Joined: 23 Apr 14 Location: Poland, Zabrze Status: Offline Points: 453 |
Post Options
Thanks(0)
|
You must calculate the angle of slope of the line.
Then determine the opening angle and length arrowhead. Calculate endpoints for each edge arrowhead and draw a triangle. Interesting task. Currently I am on vacation. I am happy to take care of this deeply when I come back, and maybe a little earlier. |
|
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600 |
|
Michael_67
Beginner Joined: 07 Aug 15 Location: DE Status: Offline Points: 10 |
Post Options
Thanks(0)
|
Thank you. That is my idea too. This should be possible with the trigonometric functions. I was just hoping someone already has a ready-made solution. Edited by Michael_67 - 07 Aug 15 at 2:39PM |
|
mLipok
Senior Member Joined: 23 Apr 14 Location: Poland, Zabrze Status: Offline Points: 453 |
Post Options
Thanks(1)
|
maybe this way:
#Region TESTING _QPDF_Arrow(10, 10, 100, 10, 10, 10, 0.1, 1) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _QPDF_Arrow ; Description ...: Draw Arrow with ArrowHeads ; Syntax ........: _QPDF_Arrow($iX1, $iY1, $iX2, $iY2[, $iArrowHeadLenPercent = 10[, $iArrowHeadAngleDegree = 10[, ; $iArrowThickness = 0.1[, $iArrowHeadThickness = 0.1]]]]) ; Parameters ....: $iX1 - an integer value. ; $iY1 - an integer value. ; $iX2 - an integer value. ; $iY2 - an integer value. ; $iArrowHeadLenPercent - [optional] an integer value. Default is 10. In relation to the length of the arrows. ; $iArrowHeadAngleDegree - [optional] an integer value. Default is 10. ; $iArrowThickness - [optional] an integer value. Default is 0.1. ; $iArrowHeadThickness - [optional] an integer value. Default is 0.1. ; Return values .: None ; Author ........: mLipok ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: http://www.quickpdf.org/forum/drawing-of-the-arrowhead-on-the-end-of-drown-line_topic3155.html ; Example .......: No ; =============================================================================================================================== Func _QPDF_Arrow($iX1, $iY1, $iX2, $iY2, $iArrowHeadLenPercent = 10, $iArrowHeadAngleDegree = 10, $iArrowThickness = 0.1, $iArrowHeadThickness = 0.1) Local $oQP If _QPDF_CreateObjectAndUnlock($oQP) = 1 Then $oQP.SetOrigin($__eQPDF_SORIGIN_TopLeft); $oQP.SetMeasurementUnits($__eQPDF_MUNITS_Milimeters) $oQP.SetLineWidth($iArrowThickness) $oQP.SetLineCap(1) $oQP.Drawline($iX1, $iY1, $iX2, $iY2) Local $iX12 = $iX2 - $iX1 Local $iY12 = $iY2 - $iY1 ; Assign a Local constant variable the approximate PI number. Local Const $PI = _Radian(180) $iArrowHeadAngleRadian = _Radian($iArrowHeadAngleDegree) ; Tan(angle) = Y / X ; Atan(X / Y) = angle Local $iArrowRadian = ATan($iY12 / $iX12) Local $iReverseArrowRadian = $iArrowRadian + $PI Local $iArrowLength If $iY12 = 0 Then $iArrowLength = $iX12 Else ; Sin(angle) = Y / Len $iArrowLength = $iY12 / Sin($iArrowRadian) EndIf Local $iArrowHeadLength = $iArrowLength * $iArrowHeadLenPercent / 100 Local $iRadianTiltedToTheRight = $iReverseArrowRadian + $iArrowHeadAngleRadian Local $iRadianTiltedToTheLeft = $iReverseArrowRadian - $iArrowHeadAngleRadian ; tg(angle) = Y / X ; ctg(angle) = X / Y ; sin(angle) = Y / $iArrowHeadLength ; cos(angle) = X / $iArrowHeadLength $oQP.SetLineWidth($iArrowHeadThickness) $oQP.Drawline($iX2, $iY2, $iX2 + Cos($iRadianTiltedToTheRight) * $iArrowHeadLength, $iY2 + Sin($iRadianTiltedToTheRight) * $iArrowHeadLength) $oQP.Drawline($iX2, $iY2, $iX2 + Cos($iRadianTiltedToTheLeft) * $iArrowHeadLength, $iY2 + Sin($iRadianTiltedToTheLeft) * $iArrowHeadLength) _QPDF_Display($oQP) EndIf EndFunc ;==>_QPDF_Arrow #EndRegion TESTING Edited by mLipok - 10 Aug 15 at 6:51AM |
|
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600 |
|
Michael_67
Beginner Joined: 07 Aug 15 Location: DE Status: Offline Points: 10 |
Post Options
Thanks(0)
|
Thank you very much! That looks pretty good. I'll translate it in C #, if I have the time. However, if the arrow direction is right to left, arrow head direction is false. And in case of a vertical line, it will lead to error in the line Edited by Michael_67 - 11 Aug 15 at 5:24PM |
|
Michael_67
Beginner Joined: 07 Aug 15 Location: DE Status: Offline Points: 10 |
Post Options
Thanks(0)
|
My Function in C# (simplified, arrow head only, fix angle and length):
private static void DrawArrowHead(double startX, double startY, double endX, double endY) { double headAngleDegree = 15; double headLength = 10; var headAngle = headAngleDegree * (Math.PI / 180); var deltaX = endX - startX; var deltaY = endY - startY; double lineSlopeAngle; if (deltaX == 0) { if (endY > endX) { lineSlopeAngle = Math.PI / 2; } else { lineSlopeAngle = -Math.PI / 2; } } else { lineSlopeAngle = Math.Atan(deltaY / deltaX); } if(deltaX >= 0) { lineSlopeAngle += Math.PI; } var rightLineAngle = lineSlopeAngle + headAngle; var leftLineAngle = lineSlopeAngle - headAngle; var rightLineEndX = endX + Math.Cos(rightLineAngle) * headLength; var rightLineEndY = endY + Math.Sin(rightLineAngle) * headLength; var leftLineEndX = endX + Math.Cos(leftLineAngle) * headLength; var leftLineEndY = endY + Math.Sin(leftLineAngle) * headLength; pdfLibrary.DrawLine(endX, endY, rightLineEndX, rightLineEndY); pdfLibrary.DrawLine(endX, endY, leftLineEndX, leftLineEndY); } |
|
mLipok
Senior Member Joined: 23 Apr 14 Location: Poland, Zabrze Status: Offline Points: 453 |
Post Options
Thanks(0)
|
Can you show example of parameters, for my function ?
|
|
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600 |
|
Michael_67
Beginner Joined: 07 Aug 15 Location: DE Status: Offline Points: 10 |
Post Options
Thanks(0)
|
Vertical line:
_QPDF_Arrow(100, 20, 100, 200 ...
$iX12 = $iX2 - $iX1 is in this case 0, $iY12 / $iX12 - division by zero Right to left: _QPDF_Arrow(100, 20, 10, 200 ... X2 < X1 draws not <--- but >--- Best Regards Michael |
|
mLipok
Senior Member Joined: 23 Apr 14 Location: Poland, Zabrze Status: Offline Points: 453 |
Post Options
Thanks(1)
|
ah I see.
You have right. But I do not worry about this as my dev.environment take care about that, and all works properly :) Edited by mLipok - 12 Aug 15 at 1:31PM |
|
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600 |
|
Michael_67
Beginner Joined: 07 Aug 15 Location: DE Status: Offline Points: 10 |
Post Options
Thanks(0)
|
C # is much more restrictive in this case :) Thank you again. You have helped me a lot with your algorithm. Edited by Michael_67 - 12 Aug 15 at 4:04PM |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store