0

I am working on a Geometric shapes project (using assembly language). I have a text file contain the coordinates of the line that are intersected at some points . through these intersections I should recognize the shape if it is a rectangle or square or triangle and print out the number of rectangles in this file of coordinates and the number of triangles and the number of square .

for triangle : I should have 3 intersections for rectangle and square : I should have 4 intersections then I should check for the distance is the 4 side are equal in length so its square else its a rectangle

I stored the data of the file in an array of struct this struct called line and contain 4 variable x1,y1,x2,y2

now I have the struct filled with the right data

My own main problem is calculating intersection between the lines What should I do to solve this problem ? I need it coded please

;;;;;;;;;;; DECLARING STRUCT ;;;;;;;;;;
line    struct 
x1      byte   ?
y1      byte   ?
x2     byte   ?
y2     byte   ?
line    ends
    // that's the function for storing tha numbers in an array of struct 
    // the array final deals with the part of code that I read from the file 
    //   with and contain the values but reversed so when i fill my array of 
    // type line I reverse the array final
    Store PROC
 mov  ebx, offset final
 add ebx,count1
 mov  edx, offset array_of_lines


 mov  ecx,10
 l_struct:
        mov     al, [ebx]
        mov     (line ptr [edx]).x1 , al
        dec     ebx
        mov     al, [ebx]
        mov     (line ptr [edx]).y1 , al
        dec     ebx
        mov    al, [ebx]
        mov     (line ptr [edx]).x2 , al
        dec     ebx
        mov    al, [ebx]
        mov     (line ptr [edx]).y2 , al
        dec     ebx
        add     edx, sizeof line
 loop l_struct

that's the text file that I have been given to know how mush rectangles in it squares and triangles

20 20 30 50 
10 10 50 50 
10 10 30 50
20 20 40 20
40 20 30 50
40 20 40 60
40 60 100 60
100 50 105 50
100 60 100 20
100 20 40 20
*

Now I need to know a simple way to find the intersection and to handle all the cases also ..

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
marie
  • 17
  • 2
  • 1
    given 2 line segments, [How do you detect where two line segments intersect?](https://stackoverflow.com/q/563198) – Peter Cordes Dec 19 '18 at 20:39
  • 1
    Please [edit] your question title to something descriptive. *Assembly project* provides absolutely no useful information. *assembly* is available from the tags, which leaves *project*. Your title should describe the problem you're having or question you're asking, and should be clear enough to be of use to a future user of this site who is scanning a list of search results to try to find a solution to a problem. Thanks. – Ken White Dec 20 '18 at 01:19
  • Use analytical geometry formulas. But then you have line coordinates as bytes (0..255 values), but the intersections are highly likely to be located on fractional coordinates like 15.23, so one of the problems you will have to decide/resolve is how accurate your code will be, and what type of numbers it will use for calculations (rounded/truncated integers, or some kind of `float` type and then how accurate?). And then the whole task is not as trivial as it may seem (if you need to ask how to calculate intersections, then the task is quite advanced for you, needs serious amount of time+effort) – Ped7g Dec 21 '18 at 00:51

0 Answers0