0 votes

Hı there,
well im not sure if it works but i tough about how to make godot detect that what i draw is a circle or not, using the angle between two points.

this is my draw:
image

i thought if i get the every angle between between closest points, and if any of them are not 90 degree or close to 90 degree, its means that angle is smoot, like this:

draw

and in the end what we have will be a circle, at least that what i thought.

is this doable?
i mean i did try few things with angle_to_point or $node.get_angle_to
but cant reach the points one by one, or add them to an array so that i can reach them from there, but couldn't do that to. And i couldn't found any example or tutorial on the net either.

so here i am, is this doable? or are there a diffrent way to make godot detect that what draw is, a circle ?

this is how i draw,

extends Node2D
var touch_position = Vector2()
var current_touch = Vector2()

var point_draw

func _input(event):

    if event is InputEventScreenTouch and event.is_pressed():
        touch_position = event.get_position()

    if event is InputEventScreenTouch and not event.is_pressed():
        $line_delete_timer.start()

    if event is InputEventScreenDrag:
        current_touch = event.get_position()


    if event is InputEventScreenDrag and not event.is_pressed(): 
        yield(get_tree().create_timer(0.25),"timeout")
        current_touch = null


func _process(delta):
    if current_touch:
        print (current_touch)
        point_draw = current_touch
        $draw_line.add_point(point_draw)
        if $draw_line.points.size() > 70:
            $draw_line.remove_point(0)

func _on_line_delete_timer_timeout():
    $draw_line.clear_points()
    $line_delete_timer.stop()

and this are nodes:
nodes

Godot version 3.2.2 stable
in Engine by (94 points)

i think i made a little progress, but not sure solve it or not :D

i add this code:

func _process(delta):
    if current_touch:
        point_draw = current_touch
        $draw_line.add_point(point_draw)
        var all_points = $draw_line.points

    for point_angles in range(all_points.size() - 1):
        var angle_result= abs(current_touch.angle_to_point($draw_line.points[point_angles-1]))
        print (rad2deg(angle_result))

right now im getting results as a degree, but not sure its the degree of the one point to another, if it is, i need to make something like
if (point1degree - point2degree == 3 or 5 its means there is a smoot line. so it can be part of the circle.

but am a noob so not sure the returned value is the value that i seek. i mean its looks close that what i want, but i feel something is not right. :D.

this is output :
https://streamable.com/ct0zev

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.