Im trying to subtract a cylinder from a intersection in openscad - intersection

This is what i have so far. I haven't been able to figure out how to subtract the cylinder from the intersected piece.
union(1){
intersection(){
cylinder(h=2,d=5, center=true);
cube([7,2,2], center=true);
}}
difference(){
cylinder(h=3,d=1,center=true);
union(1);
}

This is the solution to my problem. If it helps anyone can use as you want since i answered my own question.
difference(){
cylinder(h=2,d=4,$fn=48,center=true);
cylinder(h=3,d=1.5,$fn=48,center=true);
translate([0,2,0]){
cube([5,2,3],center=true);//right side
translate([0,-4,0]){
cube([5,2,3],center=true);//left side
}}}

I think you are little confused. There is no reason for not able to subtract cylinder from an intersected object.
$fn=48;
difference()
{
intersection()
{
cylinder(h=2,d=4, center=true);
cube([7,2,2], center=true);
}
cylinder(h=3,d=1.5,center=true);
}

Related

Tally Up Number of Occurrences in Angular

So basically I have this quiz app im working on using angular and I want to tally up the amount of times the right answer is entered. I already made it so the words 'CORRECT' are displayed by the question if they type the right answer in the text box, but I want to see how many times that happens. Here is my code
div ng-repeat="q in questions">
<span>{{ q.question }}</span><br>
<input type="text" ng-model="q.ans" name="email" placeholder="">
<div ng-show="q.ans===q.answer">CORRECT!</div>
<div>
so basically questions is just an array with a question string and answer string. I want to see at the end how many are correct. So I'm thinking, I added in a correct property to the question objects that has a default of 0 which could mean wrong, and change when its right to 1.
Now how would I make it change from the html page here when someone types the right answer? like if correct is shown, if the ng-show is right, then that value would be 1, if not, it'd be 0.
thanks for any assistance. Wondering if I could do this in real time instead of having a 'check' button at the end.
EDIT: okay I looking around the ng-if directive, would it somehow be possible to add like
<div ng-if="q.ans===q.answer">{{ q.correct = 1 }} </div>
or somehow execute that q.correct = 1 (meaning that answer is correct) if the ng-if block is run?
Make a filter for counting the correct answers
// app is your module
app.filter('correctCount', function() {
return function(questions) {
return questions.reduce(function(count, q) {
return count + (q.ans === q.answer ? 1 : 0);
}, 0);
};
})
Then you can display the total in your template
Total: {{questions | correctCount | number}}
Demo ~ http://plnkr.co/edit/br3fxHQ8q04ajZj6Fxch?p=preview
An alternative to reduce that might be easier to understand is...
return questions.filter(function(q) {
return q.ans === q.answer;
}).length;

how to connect a number variable to dynamic text in actionscript 3.0?

i know this might be simple but i have been searching everywhere for a fix but i just cannot find it!
i want to make something like a health #, so when you press whatever button the dynamic text # will go up or down. on my test project i have two layers, the first with the following code
var hp:Number = 100;
health.text = String hp;
hp being the variable, and health being the dynamic text. then i have the next layer with the button with:
function button(e:MouseEvent):void
{
hp -= 10;
}
without that second chunk of code, the dynamic text will appear, but once that is added it will disappear and the button is function-less.
how do i make this work??? once again sorry if this is a dumb question, i'm just very stumped.
The accepted answer is good, but I wanted to point out that your original code was actually very close to being correct, you just needed parenthesis:
health.text = String(hp);
For most objects String(object) and object.toString() has the same effect, except that object.toString() throws an error if object is null (which could be desirable or undesirable, depending on what you expect it to do).
This is not correct:
health.text = String hp;
use:
health.text = hp.toString();
and:
function button(e:MouseEvent):void
{
hp -= 10;
health.text = hp.toString();
}

Character hitTest Wall

The problem with my current platform game project is that the character stops before hitting a wall on the character's left side, and stops too late on the right side of the character.
Here is the script related to the problem:
char.topBumping=false;
char.bottomBumping=false;
char.leftBumping=false;
char.rightBumping=false;
char.speed=0;
char.maxSpeedConstant=10;
char.minSpeedConstant=-10;
char.xVel=0;
char.yVel=0;
stage.addEventListener(Event.ENTER_FRAME,EnterFrame);
function EnterFrame(e:Event){
//local points
top_left_point_local = new Point(char.top_left.x,char.top_left.y);
bottom_left_point_local = new Point(char.bottom_left.x,char.bottom_left.y);
top_right_point_local = new Point(char.top_right.x,char.top_right.y);
bottom_right_point_local = new Point(char.bottom_right.x,char.bottom_right.y);
//global points
top_left_point = new Point(char.localToGlobal(top_left_point_local).x,char.localToGlobal(top_left_point_local).y);
bottom_left_point = new Point(char.localToGlobal(bottom_left_point_local).x,char.localToGlobal(bottom_left_point_local).y);
top_right_point = new Point(char.localToGlobal(top_right_point_local).x,char.localToGlobal(top_right_point_local).y);
bottom_right_point = new Point(char.localToGlobal(bottom_right_point_local).x,char.localToGlobal(bottom_right_point_local).y);
if(ground.hitTestPoint(top_left_point.x,top_left_point.y,true)){
char.leftBumping=true;
}
if(ground.hitTestPoint(bottom_left_point.x,bottom_left_point.y,true)){
char.leftBumping=true;
}
if(!ground.hitTestPoint(top_left_point.x,top_left_point.y,true)&&!ground.hitTestPoint(bottom_left_point.x,bottom_left_point.y,true)){
char.leftBumping=false;
}
if(ground.hitTestPoint(top_right_point.x,top_right_point.y,true)){
char.rightBumping=true;
}
if(ground.hitTestPoint(bottom_right_point.x,bottom_right_point.y,true)){
char.rightBumping=true;
}
if(!ground.hitTestPoint(top_right_point.x,top_right_point.y,true)&&!ground.hitTestPoint(bottom_right_point.x,bottom_right_point.y,true)){
char.rightBumping=false;
}
if(char.rightBumping){
if(char.xVel>0){
char.xVel=0;
char.speed=0;
}
}
if(char.leftBumping){
if(char.xVel<0){
char.xVel=0;
char.speed=0;
}
}
char.x+=char.xVel;
char.y+=char.yVel;
}
Has anyone else encountered this problem? Any help will be much appreciated.
Update:
This is the heart of the problem, for some reason the character hitting the left wall comes out true here even while the character is standing still (left is not being pressed).
Well, after many aggravating hours I finally solved the problem. The orientation of the inside of a movieclip determines its overall position. I never knew that. I always thought it didn't matter how the inside of a movieclip was positioned in relation to the movieclip's center. Lesson learned, always center the inside of movieclips to the mc's stage to simplify things.

How to remove column number from p:barChart

I am using primefaces p:barChart which is a part of the jqplot api.
I want to remove the column number (the lest number 1 ) from the jqplot-highlighter-tooltip()
I assume the answer is in one of the options in the following
http://www.jqplot.com/docs/files/jqPlotOptions-txt.html but I didn't find the correct one
Can someone can please point me to the relevant attr ?
Thanks
function ext() {
this.cfg.highlighter = {
tooltipAxes: 'y'
};
}

Clustering similar values in a matrix

I have an interesting problem and I'm sure there is an elegant algorithm with which to solve the solution but I'm having trouble describing is succinctly which would help finding such an algorithm.
I have a symmetric matrix of comparison values e.g:
-104.2732 -180.3972 -130.6969 -160.8333 -141.5499 -139.2758 -144.7697 -114.0545 -117.6409 -140.1391
-180.3972 -93.05421 -171.618 -162.0157 -156.8562 -156.3221 -159.9527 -163.2649 -170.127 -153.2709
-130.6969 -171.618 -101.1591 -154.4978 -143.6272 -116.3477 -137.2391 -125.5645 -128.9505 -131.6046
-160.8333 -162.0157 -154.4978 -96.96312 -122.7894 -141.5103 -127.7861 -149.6883 -153.0445 -130.2555
-141.5499 -156.8562 -143.6272 -122.7894 -101.7487 -141.451 -123.9087 -138.7041 -139.2517 -125.3494
-139.2758 -156.3221 -116.3477 -141.5103 -141.451 -99.99486 -134.6553 -132.7735 -138.7249 -134.1319
-144.7697 -159.9527 -137.2391 -127.7861 -123.9087 -134.6553 -100.0683 -141.3492 -138.0292 -120.5331
-114.0545 -163.2649 -125.5645 -149.6883 -138.7041 -132.7735 -141.3492 -106.8555 -115.58 -139.3355
-117.6409 -170.127 -128.9505 -153.0445 -139.2517 -138.7249 -138.0292 -115.58 -104.9484 -140.4741
-140.1391 -153.2709 -131.6046 -130.2555 -125.3494 -134.1319 -120.5331 -139.3355 -140.4741 -101.3919
The diagonal will always show the maximum score (as it is a self-to-self comparison). However I know that of these values some of them represent the same item. Taking a quick look at the matrix I can see (and have confirmed manually) that items 0, 7 & 8 as well as 2 & 5 and 3, 4, 6 & 9 all identify the same item.
Now what I'd like to do is find an elegant solution as to how I would cluster these together to produce me 4 clusters.
Does anyone know of such an algorithm? Any help would be much appreciated as I seem so close to a solution to my problem but am tripping at this one last stumbling block :(
Cheers!