iOS QuestionHow to draw a 30 degree line

rfresh

Well-Known Member
I know how to draw lines. What I need to do is draw a line at a specific angle, such as 30 degrees.

I don't know how to calculate the line angle for the given points of x1, y1, x2, y2?

Thanks...

klaus

Expert
You need to ne more precise on what exactly you want to draw.
x1 and y1 are the coordinates of the beginning point.
Then what limits the end point?
- an x coordinate ? then y2 = y1 + (x2 - x1) * CosD(30)
- a y coordinate ? then x2 = x1 + (y2 - y1) * SinD(30)
- the length of the line ? then
x2 = x1 + Length * CosD(30)
Y2 = y1 + Length * SinD(30)

ilan

Expert
here is a b4j code example:

B4X:
``````#Region Project Attributes
#MainFormWidth: 600
#MainFormHeight: 600
#End Region

Sub Process_Globals
Type point(x As Float, y As Float)
Private fx As JFX
Private MainForm As Form
Private cnv As B4XCanvas
Private xui As XUI
End Sub

Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.Show
Dim center As point
center.Initialize
center.x = MainForm.RootPane.Width/2
center.y = MainForm.RootPane.Height/2

Dim lineLength As Int = 200

cnv.Initialize(MainForm.RootPane)

circleMekuvkav(center,lineLength/2)

cnv.DrawLine(center.x,center.y,center.x+lineLength,center.y,xui.Color_Black,2) '0 deg line
cnv.DrawLine(center.x,center.y,center.x+(lineLength*CosD(-30)),center.y+(lineLength*SinD(-30)),xui.Color_Black,2) '30 deg
End Sub

Sub circleMekuvkav(p As point,r As Int)
cnv.DrawCircle(p.x,p.y,r,xui.Color_Red,False,1)
For i = 0 To 360 Step 5
cnv.DrawLine(p.x,p.y,p.x*((r*2)*CosD(i)),p.y*((r*2)*SinD(i)),xui.Color_White,5)
Next
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub``````

Attachments

• f3.jar
407 KB · Views: 103
Last edited:

rfresh

Well-Known Member
Thank you Ilan...

Replies
23
Views
5K
Replies
0
Views
2K
Replies
8
Views
9K
Replies
11
Views
2K
Replies
6
Views
2K