33 AnswersNew Answer
Mσみคოคの ʝคงค๔ คłıķみσňı I think it is already explained, but here is a shorter one: The way I did was that I used horizontal lines only. With x1 and x2 being the limit how far the line stretches. To get x1 and x2, we need to solve the linear equations of the lines. After that, let say the top of the triangle has coordinates (10, 80) and the bottom a coordinates (40, 120). You can clearly see that the horizontal lines should be between 80 and 120. We loop throught these two values, and each time replace y in the line equations to get x1 and x2. It's just basic math, but implementing them in programming was a bit tricky.
This question has been asked two days ago, but no one gave an answer yet. Can you send a link or image to the original challenge ?
Where did you find it ? I did try to solve it with math, using trigonometric formulas, but it seemed complicated and more related to math than programming, so I just wanted to see the challenge to know if there was some extra info that both of you could have missed
Sounds like you would draw diagonal lines pixel by pixel which get shorter the farther right you go. Conceptually like this. * * + * + - * + - < * + - < #
Okay, that's probably easier. 😅
HonFu yes, that how I thought of it too, but finding the coordinates of the horizontal lines is not as obvious as it seems
HonFu no, it is the same idea as yours, it's jst that you have to take in consideration different types of triangles, and different angles
4. (Continuation) and at the same time you loop throught the X1_Coordinates and X2_Coordinates, and you create multiples lines using this coordinates I know this can be confusing, I'll try to write a working code as soon as I can
Roxana that would only work if the bottom line was horizontal, otherwise you'll get completly messed up shape
Roxana I think I have solved it, but I didn't give it much tests, and the code is badly written. Do you just want the solution or you still gonna try ?
Mσみคოคの ʝคงค๔ คłıķみσňı actually I would prefer it much better to see you try and solve it. I don't usually give codes just like that, but since this, in my opinion, is more about maths that programming, I think I'll make an exception. If you have any problems with the code, you can ask here so I can clarify, even thought I already explained everything in the text above. Here is the code: https://code.sololearn.com/cj8mx4uj7nFY/?ref=app This code was for testing purposes, so I didn't write it very well, if you still want a better version of it, ask again. I'll write it once I have free time.
Sorry, I don't know any links or image about this
Just a challenge between friends, but i can't find a fixed algorithm to find all points and create line between them, that can fill any triangle...
Yes but i need to find a algorithm that works for any triangle
The idea is: 1. You find the linear equation of all three sides of the triangle 2. Determine the highest, middle, and lowest point (you just sort them with the y coordinate) 3. This is the tricky part: The idea of this part is to draw horizontal lines, starting from the top point, here is how it goes: a) One line will contains all the x coordinates, it is the line containing the top and bottom points, finding them is easy, you just replace the y coordinate in the equation you found in step 1, let name this list X1_Coordinates (try visualizing it on a paper) b) You do the same thing for the two remaining lines, but you must repesct the order of who is on top of the other c) with all this done, comes the easiest part, all you have to do now is concatenate the two lists you got in the final steps, there you got your X2_Coordinates list 4. Finally, you loop throught the y coordinates in range(Yi, Yj) with Yi and Yj being the y coordinate of the highest and lowest points respectivly (continued)
Aymane Boukrouh [Unavailable] I think i get it my own idea was line equation too but it didn't work on my way; i just make a 6 list for all of that 3 line's points and try to create line between them but it doesn't work well.
Aymane Boukrouh [Unavailable] Thank you so much, I'll try it.
Aymane Boukrouh [Unavailable] Thank you for taking the time.I hope we get the result ❤️💛
Mσみคოคの ʝคงค๔ คłıķみσňı no problem, as I said I haven't tried many examples, but so far all the 10 test were successful on my laptop. If a test case gives a messy shape, give me the coordinates you tried it with so I can debug my code
Aymane Boukrouh [Unavailable] In the first test in line eight gives a syntax error