Search code examples
drawinglivecodepolygonscadgraph-drawing

Drawing lines with dimensions In Livecode


I am trying to write a small drawing program with Livecode, that will show the length of the drawn line over the line so it is available for editing, I also need to display the angles of the polygon for editing. The user should be able to select one section of the polygon by clicking on the dimension. This will load the length of the line into the field on the right for editing. Once the correct number is entered the drawing will redraw itself. (I can probably figure this part out using the "points" of the polygon) I have included a screen shot of what the program should look like. I was hoping that it would display these figures as the image was being drawn by the user. I am sorry I have not included any code, however I don't even know where to start. I have written several programs involving databases, but this is my first attempting to use drawings. Thanks in advance for any advice!! https://i.sstatic.net/gfKS9.jpg


Solution

  • To get the angle you can use some trigonometry. if you have two points (which you can get by using

     the points of graphic "myPolygon"
    

    Then you get one point per line. If you want to calculate the angle between two points you can use some trigonometry. If you have a point x1, y1 and another point x2,y2 you get the angle by using

    put atan2(y2-y1, x2-x1) into tRad
    

    The angle will be in radians from -pi to +pi so you need to convert it to degrees if you want more "regular" degrees:

    put tRad*180/pi into tDeg
    

    The angle you get is according to the x-y coordinate system. So if you want the angle between to lines you need to do two calculations and add the angles.