Dice numbers complemention - math

I want to program a dice which show me the right numbers like a real one. I know that the added numbers across from each other are 7.
But when I know 4 opposite numbers of the dice, how do I figure out where the two last one belongs?
For example:
https://de.wikipedia.org/wiki/Spielw%C3%BCrfel#/media/Datei:Craps.jpg
I know that on the top is a 6, and on the left side is 2. How do I know that on the right side is a 4 and not a 3?
Is there a possibility to figure this out without hardcode all possibilities?

Typical dice are "right-handed" (see: en.wikipedia/Dice#Construction). That is, one way to see it is:
Star with a blank cube (whatever way you'll represent it)
Pick any face, label it "1"
Move to any adjacent face, label it "2"
Turn 90º in the positive direction
positive defined by the right-hand rule, meaning rotate to the left (yes, confusing, and don't get me started on counter-clockwise... :-))
Move forward to the next face, label it "3".
Label the remaining faces by the "opposites add to 7" rule

Related

How can I scale a glyph down vertically while keeping the vertical stroke widths the same (and not altering any of the horizontal dimensions)?

I'm using FontForge. I'm modifying the lower case q to make a straight-stalked 9. The q has 2 logical parts, the stalk, and the 'c'. The 'c' is too big vertically. How can I scale it down vertically while keeping the vertical stroke widths the same (and not altering any of the horizontal dimensions)?
I'm a novice with FontForge, so please spell out your explanation and provide step-by-step instructions. Thanks for your help.
It sounds like you want to decrease the x-height of the 'q' without changing stroke widths.
Font-forge provides a built-in tool to achieve this: Element > Styles > Change X-Height. You might like to experiment with this, but in practice it gives you very little control over the results and I would rarely use it.
Instead I would achieve this by directly modifying the nodes of the paths.
First, I would ensure that InterpolateCPsOnMotion is enabled. Double-click the pointer tool in your toolbox to access this setting.
This will help ensure that curves scale correctly (rather than distort) as you move control points. Now, I would select the nodes at the top and sides of the bowl of the q:
and use the down arrow key to move them down about half the distance you wish to decrease the height by. Then I would deselect the nodes at the side of the bowl:
and lower the remaining nodes the rest of the distance:
You will need to check the resulting appearance and possibly make tweaks to get it perfect. Note that this or any scaling technique can subtly distort the axis of modulated strokes, which you may wish to correct.
This technique presupposes that nodes are sensibly placed at the vertical and horizontal extrema of the bowl, and that you don't have extra nodes between these extrema. If you are not in this happy situation, you can add extrema by ctrl-shift-x and you can remove surplus nodes by selecting them and ctrl-m. If you can't remove extra nodes without significantly changing the shape of the bowl, you'll just have to modify these nodes by eye.
Another point: you say you're working from a "c". I'm not sure whether you just mean the C-shape of the bowl of the q, or whether you mean you are copying the actual glyph 'c'. Note that it is rare that the bowl of a 'q' will have exactly the same shape and weight as a 'c'. Typically the stroke will be somewhat lighter to achieve the right visual grey, and especial care will be taken where it intersects the stem. Often the two shapes will differ substantially.

How to know if a vector on the right hand side

Let me first define my problem,
I am working on an indoor navigation problem. So I constructed a graph to simulate possible paths. I can easily calculate the shortest path with Dijkstra and draw it on a map. So far, so good.
But this is not enough,
I need to give instruction to user to navigate him.
For example:
"Turn Right"
"Turn Left"
"Go on from the left"
To give these kind of instructions I need to know which path is on the left and which path is on the right.
And here is what I have to solve this:
1. A undirected weighted graph
2. The shortest path which contains vertices and edges
3. X and Y Coordinates of each vertices
By the way I will do this in .Net by using beacon technology.
Do you know how to separate left and right edges so I can give direction messages to user?
Thanks.
The easiest way I can think of is to take the cross product of the vector representing the direction the player is facing/traveling and the vector representing direction you want the player to go in. Whether the player must turn left or right depends on whether the result's Y-coordinate is positive or negative, but which is which depends on the handedness of the coordinate system. I would just pick one and try it. You have a 50% of being right, and it's easy to reverse if you're wrong.
Edit:
Here we see that a×b points up when a is to the right of b. However, we also see that -a×b points down. So, if a were pointing in the opposite direction—to the left—then the cross product would point down.
The dot product approach does not work in two dimensions. For this case you want to use the sign of the determinant of the matrix [A B], where A and B are your column vectors. A pseudo-code would be
c=sign(det([A B]))
Here, if c>0 is means that B is to the left. This will switch depending on the order of A and B in your matrix.

Determine whether a point is on the left or right of a line in 3D [duplicate]

I am currently trying to write a shader in unity that draws a triangular pattern around countries in a risk-styled game if both countries are not owned by the same player (visual aid to see your borders).
Right now, I'm having an issue with making the shader set the countries properly.
It always sets country 0 to the left, and country 1 to the right - country 0 and 1 are set programically.
The line, a border, can be between 0 and 359 degrees.
How I find the countries 0 and 1 is I draw 3 points to the left and right of the midpoint of the line, one .01f, one .1f and one 1f away from the midpoints in each direction, then spin them around the midpoint to the appropriate location.
After that I do an even-odd check to see if the points are inside or outside of each country, and compare the weight results (closest gets 3 points, mid gets 2, furthest gets 1, just in case someone builds a really screwed up country that flanks the other country).
In my test map, a close to equally sliced octagon, the borders showed up correctly (after I reversed the positions of country 0 and 1 in the event the angle was over 90 and less then or equal 180). Worked without a flaw, but in other maps it doesn't work very well.
Everything but the country allocation works well, so I'm curious if anyone knows of a better way to figure out which point is to the left or a spun line, or a better conceptual way to handle this.
That above is basically when I'm doing, red being left right being blue, then I'm just checking 3 different spots then weighing in the lefts and rights found with even/odding it into the appropriate countries (one at +/- .01, the other at +/- .1 and the third 1, in case of even/odd rounding issues with closeness).
I then flip them if I find that country A is to the right, as it is on the left according to the angles I had draw. (my shader renders left first and right second, hence why I do this).
which way is left/right on a line?
From last edit is this not your case. Why not use dot product?
So if the line goes in -x direction the result is negative and if in the +x direction then the result is positive. if the result is zero that means the line goes up or down only or it is juts a point. If you need specific direction instead of left/right then use appropriate a vector instead of x axis.
dot(a,b)=a.x*b.x+a.y*b.y in 2D
dot(a,b)=a.x*b.x+a.y*b.y+a.z*b.z in 3D
Image is relevant for cases where a vector is in unit size in that case the result of dot is perpendicular projection of b into a just like on image
on which side is some point?
I think this is what you need.
As you can see if you handle line (P0,P1) and point P you want to classify as triangle then its polygon winding determines also the side of the line. So for implicit axis directions:
CW(clockwise) polygon winding means right side of the line
CCW(counter-clockwise) polygon winding means left side of the line
How to get winding? ... simply compute normal vector and get its Z coordinate. Its polarity (sign) determines winding (CW/CCW or the other way around depends on the coordinate system).
normal vector is computed as cross product of the two vertices of triangle (P1-P0)x(P-P1)
No need to compute other axises just the z so:
normal.z = ((P1.x-P0.x)*(P.y-P1.y)) - ((P1.y-P0.y)*(P.x-P1.x))
Now just do if (normal.z<0) ... else ... it should never be zero unless you call it for point on the line or the line is a point ... look here at similar question: Determine rotation direction /toward/ variable point on a circle

Generate subdivided triangle-strip cube?

I want to generate a cube where each face is divided into bits, like the following image:
http://img59.imageshack.us/img59/2504/gridcube165c3.jpg
Now, I can do this pretty simply if I'm just rendering quads, by just spacing vertices along each face plane at regular intervals, but my problem comes in when I want to turn the whole thing into a triangle strip. I've just got no idea how to unwrap it programmatically- is there some pattern to unwrapping that I'd follow?
I'm thinking of starting with the vertex at the top left corner as Row 0 Column 0 (R0C0), I'd want (first triangle) R0C0, ROC1, R1C1, (second triangle) R0C0, R1C0, R1C1 and so forth, and then when I reach the end of a row I guess I'd use a degenerate triangle to move to the next row, and then when I reach the end of the face I'd do the same to start a new face.
My main problem is that I can't visualize the program loop that would do this. I can reason out which vertex comes next visually, which is how I worked out the order above, but when I try to think programmatically I just stare blankly.
Even worse, with the end product I want the generated cube to be UV-mapped with a simple cube-map unwrap (the kind that looks like a T or t).
I guess, really, the best solution would be to find a library that already does this for me.
You could take a look at Ignacio Castaño's 'Optimal Grid Rendering' even though it's not triangle strips, it may inspire you.
Otherwise, you could use NVTriStrip library and be done with it.

Calculating position for rotated image

I have a couple of images, representing tents, that look like this:
The red and blue parts on each side of the tents are doorways, and several tents can be connected together via these doorways. For example, I want to connect the two blue doorways so that they match up like in this picture:
If the first tent is stationary, around which point do I rotate the second tent and how do I calculate where to place it?
Currently, I have the upper left corner of each doorway as an x and a y value, together with the width and direction (in degrees) of the door. I'm treating the doorways as one dimensional, so they don't have heights. Would another representation suit this better? Perhaps a start point and an end point plus direction?
I'm coding this in Flex/AS3, but I'm more after a way of thinking than code, though code would be appreciated too!
Got this fixed, after many mangled braincells. What I did was to first move the registration point of each tent to the center and calculate the doorways from there. I also changed the doorways into single point representations, set in the center of each doorway.
To get the position of the second tent, I did the following:
Rotate the first tent so that the right doorway was facing north/upwards
Rotate the second tent so that the right doorway was facing south/downwards
Calculate the position of the first tent's doorway using
Calculate the position of the second tent by placing it's doorway at the same point as the first tent's doorway
Rotate the coordinate of the second tent by as much as the first tent was rotated but in the opposite direction
Image from Wikipedia: http://en.wikipedia.org/wiki/Rotation_%28mathematics%29

Resources