Print Page | Close Window

Drawing of the arrowhead on the end of drown Line.

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3155
Printed Date: 30 Apr 24 at 7:30AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Drawing of the arrowhead on the end of drown Line.
Posted By: Michael_67
Subject: Drawing of the arrowhead on the end of drown Line.
Date 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.

QuickPDF Version 11.14



Replies:
Posted By: mLipok
Date Posted: 07 Aug 15 at 1:33PM
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


Posted By: Michael_67
Date Posted: 07 Aug 15 at 2:38PM
Originally posted by mLipok mLipok wrote:

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.

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.



Posted By: mLipok
Date Posted: 10 Aug 15 at 6:44AM
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






-------------
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


Posted By: Michael_67
Date Posted: 11 Aug 15 at 8:01AM
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
Local $iArrowRadian = ATan($iY12 / $iX12)







Posted By: Michael_67
Date Posted: 11 Aug 15 at 5:26PM
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);
        }



Posted By: mLipok
Date Posted: 12 Aug 15 at 12:37PM
Originally posted by Michael_67 Michael_67 wrote:

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
Local $iArrowRadian = ATan($iY12 / $iX12)

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


Posted By: Michael_67
Date Posted: 12 Aug 15 at 12:53PM
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


Posted By: mLipok
Date Posted: 12 Aug 15 at 1:31PM
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 :)



-------------
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


Posted By: Michael_67
Date Posted: 12 Aug 15 at 4:03PM
Originally posted by mLipok mLipok wrote:

But I do not worry about this as my dev.environment take care about that, and all works properly :)

C # is much more restrictive in this case :)
Thank you again. You have helped me a lot with your algorithm.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk