Inverse sine to calculate angle from bottom of device in degrees to last touch

trig
sin_and_cos

#1

basically i want the player to move towards the last touch spot (but not snap touch to it).

similar to Scratch which has a follow last mouse click... the player is on an infinite loop moving forward 1 step at a time (which i have not shown in the following diagram):

i figure to do this, i have to work out the inverse sine (arcsin) of an angle (i have already calculated opposite / adjacent / hypotenuse [using pythag theorem]).

********PROBLEM IS HOPSCOTCH DOESNT HAVE AN INVERSE SINE FUNCTION FROM WHAT I CAN TELL AS SHOWN IN FOLLOWING SCREEN CAPTURE********

as shown (from what i have so far) i am only given the following set of operations: { sine, cosine, power (e.g. x^y), square root, basic arithmetic (+ - / *) }. i have to do it on the fly within the app itself as the player moves - so please dont tell me to use a cowculator!!

i realise the solution if player_x < touch_x then increment player_x until.... this will move in diagonals however (great for 45 degree touches) but not in a direct path. is there any other solution that doesn't involve inputting a set of trig tables (i.e. blunt force??)... I just hate the snap drag to finger!!! will hopscotch be updated with these functions at some (near) point in the future?? I'm using the free version - does the paid version have such functionality??

thanks so much!! :smiley:


#2

Thanks for the info @LanceArmstrong! And welcome to the Hopscotch Forum!!!!!!!!!!!!


#3

I was going to say use an exponent to the negative first, but I don't think it'll work thinking about it because it'd do that to the result of the sine and not the sine itself..

And no, I don't think the paid version has that. It is a school version, so all the paid characters are unlocked and you can access classrooms; it doesn't have different blocks.


#4

I don't have a lot of experience with this so I can't give you a definite answer but this might help:


Sadly, I'm not sure its possible to get inverse trig in Hopscotch.


#5

Thanks guys... this has to be the most painstaking fix known to man. (screenshot continues from calculating opp / adj / hyp as shown in earlier post, minus the change angle 'block')

Ive gone by Sine value increments of 15 - obviously increments of 1 will be more accurate (and more painstaking to 'code'). given this, the ball gradually follows my finger across the stage... and does not "snap" to my finger like the "Set Position ( last_touch_x / last_touch_y )" solutions do.

Devs of HopScotch - probs not reading this, but if you are, any chance you could sneak this onto your todo list to make the Christmas holidays even more fun for you guys???
1) inverse trig... this entire soln could be done with way better accuracy in 1 screen using either an arcsin / arccos / arctan...
2) how annoying is it using sin / cos - i get as the default everytime i place 1 of these blocks:
(100 x sin (180)) + 500..... i only want the sin function, not the default eq.. (same with cos)..., so i have to separate using a temp block... annoying.
3) LOGICAL OPERATORS (i.e. AND / OR / NOT) - yes these can ALL be done by nesting if / else with whats there...., but again, maybs dont make me work so hard!!??
4) floating point rounding function??? :wink:


Inverse Tangent / Point Toward / Clones
#6

so all that that I can't even understand unstead of using scratch's "point towards" block...


#7

correct! HopScotch app developers - can you bump this feature up the proverbial priority tree?? through adding inverse trig a "point towards block" as @justanerd says would also be trivial for you guys to include in a next update... it would enable a lot of non-trig [ :wink: ] happy young game devs to upscale their creationism... :smiley:


#8

The paid version doesn't have any extra functionality. It's a version for schools, which have a something like "Hopscoch Groups" and a couple of free characters.

: /


#9

@Rodrigo, how come you are not a leader???? I think you should be, you are part of the Hopscotch Team.


#10

Are you really good in math and science???? It seems like it because you know a lot just because of all of those numbers!


#11

Hahaha, leader of what? And why should I be the leader? Can you please explain?


#12

@Rodrigo Leader as in trust levels on the forum I believe


#13

@LanceArmstrong, found a way to calculate the angle without trig. See: http://mathforum.org/library/drmath/view/55341.html


#14

I have tried to do this but wow it's confusing!


#15

For iPad purpose, the angles does not have to be very precise. Therefore, to calculate angle A is simply A = Pi/2 - x. You can ignore all the other terms afterward.

Here's my calculation for finding the angle from the base to the last touch position:

Set Value (MyVarX) to (Last Touch X position) - (current obj X position)
Set Value (MyVarY) to (Last Touch Y position) - (current obj Y position)
Set Value (MyVarHyp) to v( (MyVarX)^2 + (MyVarY)^2 )

Based on Dr. Math article the angle A is Pi/2 - x, where x = (b^2 + c^2 - a^2) / (2*b*c). Angle A opposite to line segment "a". However this result will be in radiant. To get degrees, need to multiply A with 180/Pi. Working through all the equations and simplify all the terms, I got the angle in degrees is 90 - 90*(b^2+c^2-a^2) / (Pi*b*c).

Because Hopscotch does not deal with decimal points, I took 90/Pi to the closest integer value of 29. So, the final simplified equation is 90 - 29 * (b^2 + c^2 - a^2) / (b*c).

Because Hopscotch cannot handle such complex equation in one line, I broke up the equation as follow:

Set Value (MyTempVar) to (MyVarX^2 + MyVarHyp^2 - MyVarY^2)
Set Angle from Base to (90 - ( (29 * MyTempVar) / (MyVarX * MyVarHyp)) )

There are a lot of round off. The angle is not precise. But for touch pad purpose, it's good enough.