Activity › Forums › Adobe After Effects Expressions › Radar Detection
-
Radar Detection
Posted by Julio Crespo on March 31, 2007 at 1:03 amI allready made a nice radar screen with it “niddle” rotating with a speed of 0.5 revolution per sec. I need to put a some point representing that the radar has been detected something. Thats points have to appear exactly when the niddle come over it and dessappear a few frames later. A point positioned on 105 degrees of the radar screen have to appear when the niddle have a rotation of 105 degrees and desapaear when the niddle have 116 degrees. Is thare a expresion to control that?. Any suggestion are apreciated
thanks
Julian Sixx replied 19 years, 1 month ago 7 Members · 17 Replies -
17 Replies
-
Dan Ebberts
March 31, 2007 at 4:47 amAn opacity expression like this might do it:
r = thisComp.layer(“niddle”).rotation;
if (r < 105){ 0 }else{ ease(r,105,116,100,0) } Dan -
Darby Edelen
March 31, 2007 at 5:24 amAlright, I didn’t see the specific angle values in your post and went a little expression crazy.
So this expression would be applied to the Opacity value of a ‘blip’ layer (a single dot whose anchor point is at the dot’s center) and would reference the rotation value of the ‘niddle’ layer (called ‘Radar Line’ in my expression). It takes the position of the dot layer and converts this into an angle based on the center of the Radar Line layer, then compares this angle to the angle of rotation of the Radar Line layer… It does not fade the dot out after a certain number of frames, but instead after the Radar Line has gone a certain number of degrees. So a faster moving line (‘niddle’) would need a higher fadeAngle value. Here’s the nitty-gritty (Replace layer(“RadarLine”) with layer(“[your-layer-name-here]”):
fadeAngle = 90; //Distance in degrees from the line before the dot is transparent
maxOpacity = 100; //The maximum opacity of the dot
minOpacity = 0; //The minimum opacity of the dot
center = thisComp.layer(“RadarLine”).transform.anchorPoint; //Center of the line’s rotation
x = center[0] – transform.position[0]; //Difference in X value between the Center and our dot
y = center[1] – transform.position[1]; //Difference in Y value between the Center and our dot
rev = 0; //Boolean to control ‘reversal’ of the result of the atan function//The following statements and declarations convert the 0-90 degree results from atan into full 360 degree results
if((x <= 0)&&(y <= 0)){ rev = 1; v = 90; } if((x <= 0)&&(y >= 0)){
v = 270;
}
if((x > 0)&&(y > 0)){
rev = 1;
v = 270;
}
if((x > 0)&&(y < 0)){ v = 90; } //Use the absolute values of our X and Y differences x = Math.abs(x); y = Math.abs(y); if(!rev) t = 360 - (radiansToDegrees(Math.atan(y/x)) + v); //If we don't want to reverse our atan results then use this declaration else t = radiansToDegrees(Math.atan(y/x)) + v; //Otherwise use this one if(thisComp.layer("RadarLine").transform.rotation > 0) r = thisComp.layer(“RadarLine”).transform.rotation % 360; //If we’re in positive rotations use this declaration
else r = 360 – (Math.abs(thisComp.layer(“RadarLine”).transform.rotation % 360)); //Otherwise use this one
o = 0; //Opacity defaults to zeroif(t > r){ //Only make our dot visible if the line has passed us travelling in acounter-clockwise direction
//Change the > to a < if your line is moving in a clockwise direction d = t - r; //Difference in angle between the line and our dot o = linear(d, 0, fadeAngle, maxOpacity, minOpacity); //set the opacity based on this difference }; o; //return the opacity I uploaded a movie of this expression in action here: https://video.google.com/videoplay?docid=-6657224198412944055The nice thing about this expression is that even if you animate the position of the dot layer it will still appear correctly. Note that this expression doesn’t take into account the blip’s distance from the center of the radar line (which could be done with a fairly easy vector length check, let me know if this is a desired feature). The blip will appear no matter how far away it is from the center as long as the line’s angle is close to its own.
-
Filip Vandueren
March 31, 2007 at 10:16 amHi W,
I believe using the Math.atan2 Method would solve your ‘reversal’ problem and the 4 if/then clauses.
-
Darby Edelen
March 31, 2007 at 5:53 pm[Filip Vandueren] “Math.atan2”
I’m pretty sure that Math.atan2(y, x) is the exact same thing as Math.atan(y / x); It just does the division for you. I tried using atan2 in this expression and ended up with the same results.
-
Filip Vandueren
April 1, 2007 at 12:54 amHi W,
not to sound like a know-it-all 8-D, but this would work:
atan2(y,x) returns a value from -Pi to +Pi for any X and Y
fadeAngle = 90; //Distance in degrees from the line before the dot is transparent
maxOpacity = 100; //The maximum opacity of the dot
minOpacity = 10; //The minimum opacity of the dotcenter = thisComp.layer("RadarLine").position.value;
x = center[0] - position[0];
y = center[1] - position[1];t = (radiansToDegrees(Math.atan2(y,x)) + 270)%360;
r=thisComp.layer("RadarLine").transform.rotation%360;r > t ? linear(r,t,t+fadeAngle,maxOpacity,minOpacity) : minOpacity;
This works for clockwise rotation. The last line should be edited for anticlockwise.
The +270 is because my needle was pointing up, so it’s zero degrees (North) was different from trigonometry standard zero ( being East)I noticed an error when the Blip is closer than 90 degrees to the angle where the modulus % occurs: the value r wraps around to 360 or 0 before the linear is completed, did your script solve this ?
-
Dan Ebberts
April 1, 2007 at 1:58 amOK – here’s my entry 8^>. It seems to work for all conditions I can think of. The key setup variables are cw (true if rotating clockwise) and uv ([0,-1] if radar line starts out pointing up, [0,1] if down, [1,0] if right, [-1,0] if left).
fadeAngle = 90;
maxOpacity = 100;
minOpacity = 0;
cw = false; // true if clockwise rotation, false if ccw
uv = [0,-1]; // unit vector representing initial orientation of radar lineline = thisComp.layer(“RadarLine”);
v = normalize(position – line.position);
u = line.toWorldVec(uv);
d = cross(v,u)[2] > 0;
angle = radiansToDegrees(Math.acos(dot(v,u)));
if ((cw && d) || (!cw && !d)) linear(angle,0,fadeAngle,maxOpacity,minOpacity) else minOpacityDan
-
Darby Edelen
April 1, 2007 at 3:12 amSee… I knew I wasn’t accomplishing it in a very efficient way (; I should’ve known I was out of my league here… I’m going to back away slowly =)
-
Mike Clasby
April 1, 2007 at 7:23 pmI loved watching the battle of , wizards (from the outside looking in, as I know when I’m out of my league), but methinks you should have a gander at this oldie but goodie from Rick Gerard. I believe the target (lights up on the radar screen) is easily animatable.
https://forums.creativecow.net/readpost/2/206453?&archive=T
If the link doesn’t work, search for Radar and Gerard as author, archives.
-
Filip Vandueren
April 1, 2007 at 7:52 pmI think it’s nice to dig a little deeper sometimes, eventhough the problem can get fixed one way, it’s nice to explore what the most efficient methods of getting somewhere is.
But never hold back on volunteering a solution because you think someone else can do it better…The fora should IMO not only be about solving problems, but also about discussing strategies and Modus Operandi…
Of course, most people will only come to the forum when they have a problem…Perhaps we should think of a ‘tag’ in the Subject when it’s brainstorming time ?
Reply to this Discussion! Login or Sign Up