  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # passing expressions to curve() within a function  » r » passing expressions to curve() within a function

By : user2955414
Date : November 22 2020, 10:40 AM
I hope this helps you . I didn't mean to ask-and-then-answer, but I figured out the (an?) answer with a little bit more poking around -- it occurred to me that I hadn't tried eval yet. eval(curve(substitute(g),from=0,to=3)) does not work, but this does: code :
``````f1 <- function(g) {
eval(substitute(curve(g,from=0,to=3)))
}
f1(x^2)
``````
``````f2 <- function(g) {
do.call(curve,list(substitute(g),from=0,to=3))
}
f2(x^2)
`````` ## As3 Function for extrapolating points on a spline curve or Hermite Curve similar to keframe interpolation?

By : John BanoET
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The equation for the Hermite Curve is this:
(via Wikipedia)
code :
``````        /*
* Computes x,y values for a given traversal of a Hermite Curve
* @param t:Number - a normalized value (0.0 to 1.0) describing path traversal
* @param points:Array - an array contining the 4 points describing the curve (P0,T0,P1,T1 - always in this order)
* Anchor points are relative to they're control points
*/
private function hermite(t:Number,points:Array):Point{
var result:Point = new Point();
result.x = (2 * Math.pow(t,3) - 3 * t * t + 1) * points.x+
(Math.pow(t,3) - 2 * t * t + t) * points.x +
(- 2 * Math.pow(t,3) + 3*t*t) * points.x +
( Math.pow(t,3) - t*t) * points.x;
result.y = (2 * Math.pow(t,3) - 3 * t * t + 1) * points.y+
(Math.pow(t,3) - 2 * t * t + t) * points.y +
(- 2 * Math.pow(t,3) + 3*t*t) * points.y +
( Math.pow(t,3) - t*t) * points.y;
return result;
}
``````
``````private function quad(t:Number,p:Array):Point{
var result:Point = new Point();
var oneMinusTSq:Number = (1-t) * (1-t);
var TSq:Number = t*t;
result.x = oneMinusTSq*p.x+2*(1-t)*t*p.x+TSq*p.x;
result.y = oneMinusTSq*p.y+2*(1-t)*t*p.y+TSq*p.y;
return result;
}
``````
``````package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;

/**
* @author george
*/
public class BasicQuad extends Sprite {
private var p0:Point = new Point(0,0);
private var p1:Point = new Point(80,50);
private var p2:Point = new Point(100,100);
private var pts:Array = [p0,p1,p2];
private var t:Number = 0;
private var pt : Point;

init();
}
private function init():void{
stage.doubleClickEnabled = true;
reset();
}
private function reset(event : MouseEvent = null) : void {
graphics.clear();
graphics.lineStyle(3,0x009900,.5);
t = 0;
}
private function draw(event : Event) : void {
trace(t,pt);
if(t == 0) graphics.moveTo(pt.x,pt.y);//draw
graphics.lineTo(pt.x,pt.y);
t+= 0.015;
if(t >= 1) removeEventListener(Event.ENTER_FRAME, draw);//done
}
var result:Point = new Point();
var oneMinusTSq:Number = (1-t) * (1-t);
var TSq:Number = t*t;
result.x = oneMinusTSq*p.x+2*(1-t)*t*p.x+TSq*p.x;
result.y = oneMinusTSq*p.y+2*(1-t)*t*p.y+TSq*p.y;
return result;
}
}
}
``````
``````function quadLerp(t:Number,p:Array):Point {
var p1:Point = Point.interpolate(p, p, t);
var p2:Point = Point.interpolate(p, p, t);
return Point.interpolate(p2, p1, t);
}
``````
``````private function getYforX(x:Number,pts:Vector.<Point>):Number{
var numPts:int = pts.length;
for (var i : int = 1; i < numPts; i++) {
if(x > pts[i-1].x && x < pts[i].x) {//find the line on which the cursor lies
t = (x-pts[i-1].x)/(pts[i].x-pts[i-1].x);//ratio between the x distance from the start of the line to mouseX and the whole line (end.x-start.x)
return pts[i-1].y + ((pts[i].y-pts[i-1].y) * t);//Thales similar triangles version, cheaper version of Point.interpolate(pts[i], pts[i-1], t).y;
}
}
return -1;
}
``````
``````package {
import flash.events.*;
import flash.display.*;
import flash.geom.Point;

public class LerpPoints extends Sprite {

private var path:Shape = new Shape();
private var cursor:Shape = new Shape();
private var numPts:int = 11;
private var pts:Vector.<Point> = new Vector.<Point>(numPts,true);
private var t:Number = 0;

public function LerpPoints() {
init();
}
private function init():void{
cursor.graphics.lineStyle(10,0x009900);
cursor.graphics.drawCircle(-3, -3, 3);
cursor.graphics.lineStyle(1,0x000099);
cursor.graphics.moveTo(0, -stage.stageHeight);
cursor.graphics.lineTo(0, stage.stageHeight);
reset();
}
private function reset(event:Event = null):void{
path.graphics.clear();
for (var i : int = 0; i < numPts; i++) {
pts[i] = new Point(i*55,Math.random() * 200);//generate points
path.graphics.lineStyle(3,0);
if(i == 0) path.graphics.moveTo(pts.x,pts.y);//draw path
path.graphics.lineTo(pts[i].x,pts[i].y);
if(i > 0){//right angled triangles
path.graphics.lineStyle(1,0x990000);
path.graphics.lineTo(pts[i-1].x,pts[i].y);
path.graphics.lineTo(pts[i-1].x,pts[i-1].y);
path.graphics.moveTo(pts[i].x,pts[i].y);
}
}
}
private function update(event:Event):void{
cursor.x = mouseX;
cursor.y = getYforX(mouseX, pts);
}
private function getYforX(x:Number,pts:Vector.<Point>):Number{
var numPts:int = pts.length;
for (var i : int = 1; i < numPts; i++) {
if(x > pts[i-1].x && x < pts[i].x) {//find the line on which the cursor lies
t = (x-pts[i-1].x)/(pts[i].x-pts[i-1].x);//ratio between the x distance from the start of the line to mouseX and the whole line (end.x-start.x)
return pts[i-1].y + ((pts[i].y-pts[i-1].y) * t);//Thales similar triangles version, cheaper version of Point.interpolate(pts[i], pts[i-1], t).y;
}
}
return -1;
}
}
}
`````` ## How to use the function curve in [R] to graph a normal curve?

By : DanielTheNerd99
Date : March 29 2020, 07:55 AM
I hope this helps you . I'm trying to make a histogram in [R], and the normal curve that describes the histogram as follows: , You just need to drop the "w" argument to dnorm in curve:
code :
``````w<-rnorm(1000)
hist(w,col="red",freq=F,xlim=c(-5,5))
``````
``````w<-rnorm(1000, mean=10, sd=2)
hist(w, col="red", freq=F, xlim=10+c(-5,5))
curve( dnorm(x, mean=10,sd=2), 5, 15, add=T, col="blue")
`````` ## AngularJS Passing Expressions Into Function

By : Sachin Hegde
Date : March 29 2020, 07:55 AM
hop of those help? If you want to pass along this data, try removing the {{}} so the call will just look like
code :
``````ng-click="commentPopup(comment.comment_id)"
`````` ## Passing expressions by reference inside expressions

By : CreepyStalker2107
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , mat3 will reflect the mutation of mat1 and mat2, but not rebinding of mat1 and mat2. It is important to understand the distinction between mutation and rebinding.
Mutation
code :
``````A = [1, 2, 3]
A = 4
``````
``````A = :(f(x))
A.args = :g
``````
``````mat1 = :(f(x))
mat2 = :(f(y))
mat3 = :(\$mat1 + \$mat2)
mat1.args = :g
``````
``````x = 2
x = 3
``````
``````A = [1, 2, 3]
A = [4, 2, 3]
``````
``````mat1 = :x
mat2 = :y
mat3 = :(\$mat1 + \$mat2)
mat1 = :z
``````
``````mat1 = :x
mat2 = :y
mat3() = :(\$mat1 + \$mat2)  # function definition
mat3()  # :(x + y)
mat1 = :z
mat3()  # :(z + y)
`````` ## React error Expected an assignment or function call and instead saw an expression no-unused-expressions while passing pr

By : user2759395
Date : March 29 2020, 07:55 AM
To fix the issue you can do Look at the render method, in the else branch you create a MovieItem component, but you don't do anything with it. Looking at your code, I guess you need to assign it to movieItem variable, so it gets than rendered in the p element. 