trigonometry


How can I calculate the angle


I'm creating a game where if the enemy is in a certain range and is in front of the player the player can attack the enemy. I have worked out the radius distance and made it facing forward depending in which way the player faces but how can i create the angle so it makes like a cone shape from the player. I have got an image. The thin green line is the radius which I have worked out but how can i calculate the red cone.
Here is the image for more better understanding
http://tinypic.com/view.php?pic=28v63h0&s=6
This is what I done so far
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
public class Player extends MovieClip
{
var radius:Number = 60;
public function Player()
{
addEventListener(Event.ENTER_FRAME, Update);
}
function Update(event:Event)
{
var radiusx:Number = x+radius*Math.cos(rotation/180*Math.PI);
var radiusy:Number = y+radius*Math.sin(rotation/180*Math.PI);
// Rotate to mouse;
var dx = parent.mouseX - x;
var dy = parent.mouseY - y;
var angle = Math.atan2(dy,dx) / Math.PI * 180;
rotation = angle;
}
}
}
You can use the definition of tangent:
tan(a/2) = s/(2d)
where s is size (diamerer) of the enemy and d is the shortest distance to the enemy. Here a is the total visible angle (between two red lines).

Related Links

Best way working with trigonometric functions
Calculate place of point C to be equal distance away from points A and B
How to compute sum of angles from sine and cossine?
Counting trig ops as measure() function to fu() in sympy
Find a coordinate along a path
Angle calculation resulting in strange behavior
Shift angle orientation using atan2
estimate angle between two lines y = 1000x and y = 999x
Need help revising a simple formula to make it universal
SWIFT trig functions
Simplifying atan(tan(a+b))
2 Different Radians constant calcuations whats the difference?
Trigonometry & Sunset
Calculating collisions with Radians incrementing
How do arbitrary-precision libraries like mpmath evaluate simple trigonometric functions?
How can I calculate the angle

Categories

HOME
eclipse
eslint
requirements
gradient
grafana
cq5
vxml
square
jquery-ui
jax-ws
discrete-mathematics
computer-science
fosrestbundle
syntaxnet
windows-ce
angular-dart
firefox-addon
chargify
forgot-password
pyramid
replication
windows-xp
jquery-ias
pagespeed
postscript
exit
dapper-extensions
ceylon
sql-server-2000
angularjs-material
installshield-le
reactjs.net
least-squares
sim-toolkit
z-notation
kill
magento-1.9.3
laravel-elixir
install.packages
glm-math
phpdbg
openal
clarifai
remedy
context-switch
modelsim
universal-analytics
polyline
cvxpy
cubism.js
actor-platform
microstation
beamer
ng-grid
lua-telegram-bot
hadoop-partitioning
fuzzywuzzy
nio2
jnlua
decimalformat
terracotta
gocql
jdi
extjs-grid
binomial-theorem
dock
sql-server-data-tools
aspectj-maven-plugin
gamekit
openbabel
cosine-similarity
uncaught-typeerror
big-ip
easyrtc
verold
personalization
accesscontrolexception
rfc5322
android-usb
spring-3
solace-mq
scrypt
asdf
process-explorer
pclzip
tree-balancing
patricia-trie
iboutlet
predicatebuilder
kqueue
landscape-portrait
u2netdk
automationelement
google-ajax-api
appledoc
luajava
commerceserver2007
instantiationexception
binomial-heap
interprocess
burndowncharts
complex-event-processing
scrubyt
wcf-proxy
wspbuilder

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App