Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Geometric constructions
- gmd65
-
44 posts
Geometric constructions
I've been thinking about creating a project you can use to make geometric constructions. It starts of with a line in the middle and a unit circle. The next lines and circles are created from the intersection points as reference points. I need an algorithm to find intersection points between two lines, two circles and a line and a circle from the two x and y coordinates the line is going through/a circle's center's x and y coordinates and its radius. Does anyone know what the formula would be?
https://scratch.mit.edu/projects/315259556/
https://scratch.mit.edu/projects/315259556/
Last edited by gmd65 (June 5, 2019 19:59:13)
- JackK211424
-
500+ posts
Geometric constructions
If you are wanting to find where the intersection points are you could do this:
then you could find the intersection points by going
when green flag clicked
go to x: (line pos 1) y: (line pos 1)
add (x position) to [ xlist v]
add (y position) to [ y list v]
pen down
go to x: (line pos 2) y: (line pos 2)
add (x position) to [ xlist v]
add (y position) to [ y list v]
then you could find the intersection points by going
Intersection point 1 = (join (item (1 v) of [x list v] :: list) (item (1 v) of [ y list v] :: list)) :: #4286f4 ::
- gmd65
-
44 posts
Geometric constructions
Thanks for replying, but idk how do I make this compatible with my script. I already found out myself how I can do it for intersecting lines. But can someone show me an algorithm for between a line and a circle and two circles?
- gmd65
-
44 posts
Geometric constructions
I will implement finding intersection points later. Now I have a different problem. I implemented moving the construction using arrow keys. But every move it takes more time to redraw than the previous and I don't know why. Maybe someone could even make it faster?
- gmd65
-
44 posts
Geometric constructions
Ok, found a HUGE formula to find the intersection points. But it doesn't seem to work well. The x value shows NaN when two lines I drew are parallel, so the formula might not be that wrong. I came up with it by finding the formula for the graph of the function which contains the two points that define the straight. This is what I found:
((y2-y1)/(x2-x1)*x)+((x2-2x1)/(x2-x1)*(y2-y1)) = ((y4-y3)/(x4-x3)*x)+((x4-2x3)/(x4-x3)*(y4-y3))
Then I can find the x coordinate of the point where the two straights cross:
x = (((x4-2x3)/(x4-x3)*(y4-y3))-((x2-2x1)/(x2-x1)*(y2-y1)))/(((y2-y1)/(x2-x1))-((y4-y3)/(x4-x3)))
The formula doesn't seem to work.
Sorry for triple posting. No one would notice editing.
EDIT: found a new way. Creating new topic to be noticed.
((y2-y1)/(x2-x1)*x)+((x2-2x1)/(x2-x1)*(y2-y1)) = ((y4-y3)/(x4-x3)*x)+((x4-2x3)/(x4-x3)*(y4-y3))
Then I can find the x coordinate of the point where the two straights cross:
x = (((x4-2x3)/(x4-x3)*(y4-y3))-((x2-2x1)/(x2-x1)*(y2-y1)))/(((y2-y1)/(x2-x1))-((y4-y3)/(x4-x3)))
The formula doesn't seem to work.
Sorry for triple posting. No one would notice editing.
EDIT: found a new way. Creating new topic to be noticed.
Last edited by gmd65 (June 8, 2019 11:27:07)
- Discussion Forums
- » Help with Scripts
-
» Geometric constructions