1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

iOS Question How to draw a 30 degree line

Discussion in 'iOS Questions' started by rfresh, Jun 23, 2019.

  1. rfresh

    rfresh Well-Known Member Licensed User

    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?

  2. klaus

    klaus Expert Licensed User

    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 and Erel like this.
  3. ilan

    ilan Expert Licensed User

    here is a b4j code example:

    #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.RootPane.LoadLayout("Layout1") 'Load the layout file.
    Dim center As point
        center.x = MainForm.RootPane.Width/
        center.y = MainForm.RootPane.Height/
    Dim lineLength As Int = 200
    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)
    For i = 0 To 360 Step 5
    End Sub

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

    Attached Files:

    • f3.jar
      File size:
      407 KB
    Last edited: Jun 24, 2019
    techknight, Erel and José J. Aguilar like this.
  4. rfresh

    rfresh Well-Known Member Licensed User

    Thank you Ilan...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice