So I have a program on my TI-84 calculator that calculates the volume of 3-D shapes. Here is the code
ClrHome
Disp "Z=Cuboid
Disp "Y=Tri Prism
Disp "X=Square Pyramid
Disp "W=Tri Pyramid
Disp "V=Cylinder
Disp "U=Cone
Disp "T=Sphere
Prompt S
Pause
If S=Z
Then
Prompt W,L,H
W*L*H→θ
ClrHome
Disp "V=
Disp θ
Pause
ClrHome
Stop
End
If S=Y
Then
Prompt A,B,C,H
*formula*→θ
ClrHome
Disp "V=
Disp θ
Pause
ClrHome
Stop
End
If S=X
Then
Prompt H,L,W
*formula*→θ
ClrHome
Disp "V=
Disp θ
Pause
ClrHome
Stop
End
This is my whole programs for now, the question is that when I enter the value for S as X, (S=X) and press enter to continue, the program goes into If S=Y and asks me for A,B,C,and H. If I enter S=Z, then the program goes to S=Z no problem. If I enter S=Y, program goes into S=Y no problem. But when I enter S=X, the program goes into S=Y. Why?
It working at all is more or less accidental. This code relies on the values of the variables X, Y, Z etc to be different so they can be told apart. This is obviously a very fragile design.
Since this is a menu, you may be interested in the Menu( command:
Menu("Select Shape","Cuboid",C,"Tri Prism",TP,"Square Pyramid",SP
Lbl C
Prompt W,L,H
W*L*H
Disp Ans
Stop
Lbl TP
Prompt A,B,C,H
"dunno
Disp Ans
Stop
Lbl SP
Prompt H,L,W
"dunno
Disp Ans
I put the formula "bare" and then Disp Ans here so that the user can easily use the answer in subsequent calculations, without needlessly overwriting some variable.
Related
I designed basic clipper circuit using single 3.3v Zener.When i simulate this on proteus and while checking output by keeping knob on AC of respective chanel and output shown is 2v positive and 2v negative from refrence ground(obviously wrong).When i change knob to DC it shows correct output of 3.3 positive and 0.7 negative.I dont know why it is giving correct vaalue on DC as my Input is AC.
enter image description here
I've been trying to write a program in Processing 3, which will display points from 3D space onto the viewport. I won't be showing any code for now because the point of this question is if there are any disadvantages in my method for displaying space in perspective.
The idea behind my formula for calculating X and Y screen coordinates for a point in 3D space is to compare alpha and beta angles (angles on the picture, values don't matter right now).
Since the 0,0 coordinates on the screen starts in the upper-left corner, here's what I came up for X and Y:
where:
γ is the angle between the right edge of the FOV and CP OR just α+β
β is the Field of View half angle
α is the angle between the camera's forward vector and CP vector.
𝛿 is the same as γ but on a XZ plane (looking up and down)
This way, when:
α = 0, the X is width and that puts the point at the right edge of the screen
α = β, the X is the middle of the screen (width/2), and
α = 2β, the X is 0 and that's the left edge of the screen.
I did calculate angles using acos() and asin() functions and they were correct.
The first problem was the α angle; it never was negative, meaning that γ would never go below β since
β+α = β+0.
I managed to fix it by multiplying α with a cross product of CP and direction (on the image) vectors to determine if α is positive or negative.
At first I though I fixed the problem but as soon as I rotated the camera, the point on the screen would go to the right only to a certain value and then bounce back in the opposite direction (as if the cross product didn't work anymore or something).
Do you have any idea if there are any downsides in my formulas?
Thanks for help!
Id like to set the size of a turtle as the size of the patch it's standing on.
Even better I need turtles which are bigger as 4 or 16 patches.
If for example i have a squared world with 16x16 patches id like to have turtles that can be big 1x1 or 2x2 or 4x4 etc....
and the turtle should overlap perfectly the patches: it might be 1 patch (1x1 case), 4 (2x2 case) etc...
abott setting the size of the turtle equal to the sie of the patch for perfect overlapping in trying wit this code:
hatch-turtle 1 [set size [size] of patch-here ]
but it gives me the error:
A patch can't access a turtle variable without specifying which turtle.
Maybe try some variation of:
ask turtles [ set size patch-size ]
perhaps scaling by a multiplier as needed. Note that size is a per-turtle variable, but patch-size is a global reporter, because all patches are always the same size in pixels.
Note that size is measured in patches, while patch-size is measured in pixels.
I really don't understand at all what you're trying to do here, but the above is legal NetLogo code, anyway.
A turtle's size is measured in units of patches, so if you want your turtles to be the same size as the patches they are standing on, that's:
ask turtles [ set size 1 ]
but 1 is the default size, so in order to get this behavior, you actually don't need to do anything at all.
This answer comes years after the question was asked, but I leave it here hoping that it helps others who may encounter the same problem (as I did). Below I first clarify the problem and then offer a solution.
Clarification: It is implied by the problem that OP has defined a square shape for the turtles. The default size of square turtles in NetLogo is 1, which means that by default a square turtle should completely fill a patch. However, OP still observed blank space between square turtles that are placed next to each other. The aim of this answer is to remove that blank space for square turtles of size 1.
Solution: To solve this problem, note that the default square shape of turtles in NetLogo is made up of a colored inner area and a thick colorless border. The blank space that the OP observed between the turtles was in fact composed of the colorless borders of square shapes. In order to produce a figure with colored squares placed immediately adjacent to each other (that is, without any apparent space between them), it suffices to define a new square shape with no border. This new square shape should be defined such that the inner area of the square fills the entire patch. This can be done using the Turtle Shapes Editor from the Tools menu: find the square shape, create a duplicate of it, and modify the new shape in the graphical editor. To modify the shape, click on its top-left corner and drag that corner to the top-left corner of the graphical editor window. Then do the same with the bottom-right corner.
I'm designing a simple app to display some Cartesian type graphics using DrawLine() and DrawEllipse() functions into a PictureBox control. To make the coordinate system more "real-world" instead of the picture box I am using a matrix to flip the Y axis, scale everything down and reposition it so that (0,0) is at the center of the screen and (+2,+2) is at the upper right corner. All works well for drawing of graphics. However, in trying to read mouse events it appears that the MouseEventArgs variable (returned by most Mouse events) returns the mouse position X and Y as integers. I am properly using an inverted matrix to retrieve the coordinates at the scaled values, but at the scale I am using, this won't work as integers as I require screen positions in fractional values (1.5, 1.6, etc).
Is there no way to retrieve the mouse values as a floating point or double/decimal value that will give the "resolution" I require?
Some code fragements:
--Globally
Private MyTransform As Matrix
--Within the picturebox
Paint() event
Dim G As Graphics = e.Graphics
Dim mx As New Matrix(1, 0, 0, -1, 0, 0) 'Y-axis orientation flipped to match Cartesian plane
mx.Translate(PictureBox.Width / 2, -PictureBox.Height / 2) 'Move 0,0 to lower left corner
mx.Scale(100, 100)
G.Transform = mx
MyTransform = G.Transform
'All drawing is performed at this point and works fine.
--Within the MouseDown event
MyTransform.Invert()
'Here is the issue--the Mouse points returned, being integers, cannot properly
'show the mouse point if the transformation matrix has scaled up the drawing space at all.
e.Location.x 'is an integer, so it cannot show .01 as the proper mouse location within the transformed viewspace.
e.Location.y 'same issue.
MyTransform.Invert()
I've looked for a cartesian coordinate-based picturebox alternative to no avail, and Charting components won't work because they require the points being drawn be contained in their own proprietary containers/sets. I'm doing all the drawing myself with GDI-type methods. The only alternative seems to be to avoid doing the transformations with vb and doing all the translation/untranslation myself, unless someone has an alternative or example to suggest....?
Store the Scale as a property. Then as you change the scale you apply a function to the mouse coordinates difference. Example will use a 10/1 plane so the Scale will be 10.
Private Property Scale As Single
Function:
Private Function CorrectForScale(coord As Integer) As Single
Return (coord / Scale)
End Function
Now if the difference in distance between mouse position = 3 then the result after the function would be 0.3.
Im writing a multiplexor of 4 bits as input and 1 as output. I have tray several ways, using cases, if, etc. but I keep getting this error:
WARNING:PhysDesignRules:367 - The signal <A<2>_IBUF> is incomplete. The signal
does not drive any load pins in the design.
WARNING:Par:288 - The signal A<2>_IBUF has no load. PAR will not attempt to route this signal.
WARNING:Par:283 - There are 1 loadless signals in this design. This design will cause Bitgen to issue DRC warnings.
And when I program in my circuit design card (Basys), everything works fine, but the switch that is assign to A[2], doesnt work, here are my modules:
module Multi_4_1(
input [3:0] A,
input [1:0] S,
output Z
);
wire w1, w2;
Multi_2_1 a(.A(A[0]), .B(A[1]), .SEL(S[0]), .F(w1));
Multi_2_1 b(.A(A[2]), .B(A[3]), .SEL(S[1]), .F(w2));
Multi_2_1 c(.A(w1), .B(w2), .SEL(S[1]), .F(Z));
endmodule
module Multi_2_1(
input A,
input B,
input SEL,
output F
);
assign F = (~SEL&A)|(SEL&B);
endmodule
And this is where I assign the terminals to the card, but this I have tried it with another projects and it works fine
NET "A[3]" LOC ="B4"; # sw3
NET "A[2]" LOC ="K3";
NET "A[1]" LOC ="L3"; # sw1
NET "A[0]" LOC ="P11"; # sw0, el de la derecha
NET "S[0]" LOC ="G3"; # sw4
NET "S[1]" LOC ="F3"; # sw5
NET "Z" LOC ="M5"; # L0, el de la derecha
Your multiplexer has an incorrect design.
This is your truth table:
S=00 => Z=A[0]
S=01 => Z=A[1]
S=10 => Z=A[3]
S=11 => Z=A[3]
Thus A[2] can never be an output, so it is 'unloaded', and your synthesis tool is warning you of this. You probably intend for Mux b to use sel(S[0]).