Point ahead

Report a typo

You have coordinates of point, and a number. You need to calculate the coordinates of the new point, which are obtained as a result of moving the original point forward by a distance equal to a given number on the same straight line. The line is drawn through the original point and the origin of coordinates.

Point ahead

You will get three numbers: the x and y coordinates and the distance. Calculate new coordinates and round them before the output.

You've encountered a challenging problem — time to put your thinking cap on 💡🧢! The task statement and HINT should help you solve it; however, if this problem is too complex, you can postpone it and come back later to try and solve it.

Tip:

  • You can find the angle using atan. For the current task, it's pretty simple: tan = y / x. If you know the tan, you can find an angle by the atan: angle = atan(tan).
  • The adjacent leg is determined by the angle and distance: distance * cos(angle).
  • The opposite leg is like an adjacent, but you need to use a sin function.

Sample Input 1:

1 0 5

Sample Output 1:

6 0
Write a program in Go
package main

import (
"fmt"
"math"
)

func main() {
var x, y, distance float64

fmt.Scan(&x, &y, &distance)

// Find an angle between the line and the x-axis
angle := ? // You can find an angle with using Atan() function

// Calculate a new point
newX := x + ? // additional value is the adjacent leg
newY := y + ? // additional value is the opposite leg

// Round newX and newY to the nearest integer:
newX = math.?
newY = math.?

fmt.Println(?, ?)
}
___

Create a free account to access the full topic