# [solved] Trigonometry help needed

## Recommended Posts

Hi fellow scripters and builders!

I'm working on a control HUD to one of my upcoming projects, and I've kind of hit a dead end thanks to my insufficient trigonometry. What I need is the following:
I've got a face on the HUD. It's middle point represents a pivot. The HUD wearer can click the face, and I need to be able to get the angle (calculated from the "upwards" Z axis) from that.

The click provides coordinates in the form of a vector <u,v,0> where U is the horizontal coord, V is the vertical coord, and they both are a range from 0.0 to 1.0 - using function llDetectedTouchUV()

I'm attaching a visualization of what I have in mind. I'm sure this is a trivial problem, but for someone who had long forgotten everything about trigonometry, it's a total blocker.

Thank you to whoever will be able to help me out! ♥

Edited by LaurisFashion
Solved

##### Share on other sites

I would use llDetectedTouchST() to get the coordinates (X,Y) and use the formula cosv= vector(A) x vector(B)/length(A)*length(B) to find the angle.

To my knowledge there is no easy way to do it  - unless there are some handy LSL functions

Edited by Rachel1206

##### Share on other sites

Alright, never mind!

I've opened some old math books and ran through LSL documentation, and this is a working solution. Feel free to use it if you need to achieve a similar effect.

```integer TouchF;
vector TouchST;
float Angle;

default
{
state_entry()
{
llSetText("",ZERO_VECTOR,0);
}

touch_start(integer total_number)
{
TouchF = llDetectedTouchFace(0);
// We are using llDetectedTouchST(), because that one gets coords from the face
// while llDetectTouchUV() gets coords from texture. Since we're rotating the
// texture, that would yield ever changing wrong results.
TouchST = llDetectedTouchST(0);

// Only apply when the touch is on the interactive face
if(TouchF == 0)
{
Radian = llAtan2(TouchST.x - 0.5, TouchST.y - 0.5);

// We can use the degrees of rotation for anything later.
}
}
}```

##### Share on other sites
2 minutes ago, Rachel1206 said:

I would use llDetectedTouchST() to get the coordinates (X,Y) and use the formula cosv= vector(A) x vector(B)/length(A)*length(B) to find the angle.

Thanks!

The llDetectedTouchST() is definitely a good call. I tried the UV version and since I'm rotating the texture on that face, it was giving me crazy wild results.
On the other hand I used llAtan2(), which seems to be made specifically for such a purpose

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×
×
• Create New...