Mathematical question - Need help

Hello,

i have a custom class with the following properties:

  • xOffset As Double
  • Angle As Integer

Now I want to draw an instance of this class in the Graphics object and have to calculate the coordinates for the instance. How does the calculation of the instance coordinates look like from the given properties?

Example:
The main text is drawn at position 100, 100.
xOffset for the instance is 5 and Angle is 45 degrees. How is the x, y position for the instance calculated?

Thanks

Is xOffset the horizontal distance between the two points (let’s name them reference and endpoint) or is it the total offset?

How is the angle defined (clockwise or counterclockwise rotation?)

Is the Y axis pointing downwards? (are you using Xojo’s vertical coordinates?)

If the answers to my three questions are: total distance, clockwise, downwards, then:

Xend = Xref + xoffset*cos(Angle)
Yend = Yref + xoffset*sin(Angle)

If the answers are different these will most probably not work (unless both the angle and the Y axis are inverted).

EDIT: The angle must be passed in radians to the cos() and sin() functions.

Julen

1 Like

Good morning @Julen_I,

thank you very much. It works exactly as desired. Made my day :slight_smile:

T H A N K S

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.