If I have a box at 10,10 to 20,20 , I could draw two diagonals
Using drawline is easy
Now if I have a vector Ovalshape or pixmap shape, and I want that to be the diagonal, I need to make the width
sqrt((x1- x2)^2 + (y1- y2)^2 )
If its a true square, the rotations are 2.35619 ( \ ) and 0.785398 ( / )
But if it isnt a square, does anyone have the math to work out the correct rotation in radians?
can you rephrase you question? perhaps mock-up a graphic example
if rotation is based on the center of the object, then it makes no difference if it is square or rectangular
Wouldn’t those be the angles of the rectangle the oval touches?
if L is length, and W is width, and C is the result of your equation above (C = sqrt(L^2 + W^2));
wouldn’t the angles be acos© and asin©
Not really. Think angles…
If its square, the rotation is obviously 45 degrees (the two radian figures above are 45 degrees and 135 degrees)
If its rectangular, then the angle gets closer to 90 as the width increases.
If sin(x) = height/width (opposite over adjacent)
then I guess I need asin (height/width) rather than asin (hypotenuse)
exactly what are you trying to rotate then?
As Lanque mentioned… an oval can be encased in a rectangle (as a matter of fact that is how Xojo draws a “normal” oval)
are you trying to rotate the “object”? or each point along the path of the object
I have a variety of vector shapes.
Long thin ovals, lines, pixmaps, arrows…
I want to rotate them so they lie corner to corner.
That would mean 45 degree angles if the bounding area was a square.
So I need another angle, in radians
So I need to know the object2d rotation that is needed to get these two diagonals, for a line that starts life as horizontal.
You need trigonometry. The tangent of an angle gives you the rise divided by the run (vertical divided by horizontal). Since you know the height and width, you need the inverse tangent (aka atan) function to get the angle.
angle = atan(height/width)
The result is in radians, which is what you need.
Thats the one!
I’d managed to convince myself that “opposite over adjacent” was sin() and couldnt understand why the return values were so wrong.