• Create Account

# AhmedCoeia

Member Since 21 May 2012
Offline Last Active Yesterday, 08:58 AM

### Explaining mathematical concept

19 April 2014 - 02:22 AM

Hi All,

I was trying to use Unity3d directional light and use it to transform a mesh of 6 vertices(two quads) which is projected on a floor, this mesh is used as a shadow for a 3D Object.

Someone suggested to project the light vector onto that plane and use that vector to translate the vertices. I wish I visualize that concept, because I can't get it all, how come a vector will be projected onto that plane and use it to translate the vertices left or right and shear them?

I have watched Khan Academy projecting a line onto a line and I got it totally.

### Quaternions rotation code

09 April 2014 - 09:11 AM

I have seen that piece of code, but I don't get it what's really doing, in mathematical way. Source is a 3D Model of a bike. The normal comes from a ray casting to the ground, and mFrontWheelNormal, is coming from another ray casting.

I'm using Unity3D.

```Quaternion rotFront =
Quaternion.AngleAxis(Source.rotation.eulerAngles.y, normal) *
Quaternion.FromToRotation(new Vector3(0, 1, 0),
mFrontWheelNormal.GetVector3());
```

### Advice on Getting better on General Programming

24 March 2014 - 03:19 AM

For the 5 years I worked for various companies, I worked in large software like computer vision kits, embedded, games. I found myself very good at debuggins skills, I've even found and fixed bugs in frameworks and I solved them. The problem is that I'm very weak at problem solving. I got interview with Qualcomm, and they said you're fine at software, but you have a limited problem solving, I also had the same results with Google.

I'm very bad at solving puzzles and brain teasers. During the interviews I solve all of the software related problems on the blackboard, but when I went to the GM and face math problems and probabilities, I struggle.

How can I improve my problem solving skills?

Some of the problems:

1. A cake that is cut from anywhere and needs just one cut to halved in equal. I told him cut it horizontally, he said No, consider it as a 2D Problem!.

2. Consider a concenteric 3 circles, each one can get a color, but not matched with the other circle, how many blobs you can make out of those circles ? this was with the GM ( Augmented Reality SDK)

3. Consider a train, an infinite one, and you looked at the window, and there are two cars, one big, and one small, what is the probability of having only a big car, I said 50%, he said, what if that two cars you dont know their length, and you want to get the probability of getting the biggest one, I struggled, didn't solve it... I was really exahusted after long day of interviews

4. prob of having a number divisible by 5 in numbers from 1 to 100.. struggled!!

All coding questions I solved them like reverse a string, detect a cycle in a linked list,..etc.

### How to know where light is projected or facing an object

22 March 2014 - 05:38 AM

I have an object, actually its a bicycle, and I have a directional light source in the scene. I would like to know from the light source directional vector and object's orientation, where the light is affecting the object, so that I can project the blue quad on the side of the projection.

B  X  D

Where X's are the center of the bike, and I calculated them as my current position + forward vector or - forward vector's length.

If the bicycle is facing the light source, the quad should be projected and reflected on the surface of the ray of the incidents, otherwise, it should be in the other side, at the same time based on how much is the light on each side, the relevant quad should be stretched and the other quad should be scaled down, to simulate a fake shadow effect.

I have written a code for it, but the scaling of the shadow is not stable at all, like one side scales up or down, and the other gets stretched,..etc

mLean is a variable from -0.5f to 0.5f, that determines how much is the biker has leaned by pressing the key left or right.

```// LightDir.Up Model vector
float leaningAngleUpVector = Vector3.Dot(lightDir.normalized, Source.transform.up.normalized);
float lightAngleRightVector = Vector3.Dot(lightDir.normalized, Source.transform.right.normalized);

Global.Log("Current Leaning" + leaningAngleUpVector.ToString("0.00"));
Global.Log("incidentLightAngle" + lightAngleRightVector.ToString("0.00"));

// light projected left side
if (lightAngleRightVector < 0)
{
if (mLean > 0.1f)
{
Global.Log("I'm leaning left");
vxCDRight = Mathf.Clamp(mLean, 0, 0.3f); // shrink left side 0.5f<lean>-0.5f
vxABLeft = Mathf.Lerp(0, Mathf.Clamp(leaningAngleUpVector, 0, 0.4f), Time.deltaTime * 4); // extend the other side

}
else
{
vxABLeft = -Mathf.Clamp(Mathf.Abs(lightAngleRightVector), 0, 0.4f);
vxCDRight = 0;
Global.Log("left leaning only");

}

}

// light projected right side
else if (lightAngleRightVector > 0)
{
if (mLean < -0.1f)
{
Global.Log("Im leaning Right");
vxABLeft = Mathf.Clamp(mLean, -0.3f, 0); // shrink left side 0.5f<lean>-0.5f
vxCDRight = -Mathf.Lerp(0, Mathf.Clamp(leaningAngleUpVector, -0.4f, 0), Time.deltaTime * 4); // extend the other side
}
else
{
vxCDRight = Mathf.Clamp(lightAngleRightVector, 0, 0.4f);
vxABLeft = 0;

Global.Log("Right leaning only");
}

}
Vector3 vxPos1Top = pos + rot * (new Vector3(-offsetX + vxABLeft, 0, offsetY) * scale); // 1,2 vertices or on its left
Vector3 vxPos2Top = pos + rot * (new Vector3(-offsetX + vxABLeft, 0, -offsetY) * scale);
Vector3 vxPos3Top = pos + mForward.GetVector3().normalized * mMiddleScale; // two middle vertices
Vector3 vxPos4Top = pos - mForward.GetVector3().normalized * mMiddleScale;
Vector3 vxPos5Top = pos + rot * (new Vector3(offsetX + vxCDRight, 0, offsetY) * scale); // 5,6 vertices are on the right of the bikeer
Vector3 vxPos6Top = pos + rot * (new Vector3(offsetX + vxCDRight, 0, -offsetY) * scale);```

### Projecting a Quad from light source and Normal Vector

04 March 2014 - 01:51 PM

Hi All,

I'm having a decal mesh( a quad) which has a shadow texture. and I have a bike, which has its forward direction, I have the normal to the ground, and normal touching point to ground. I have also the direction of light.

My quad on the floor has 4 vertices, so I assumed as the figure Points C,D is set to be parallel with the front wheel and the back wheel.

I would like to get the maths and get the points A, B  with respect to the light direction.

My current code is : I would like to determine both vxPosSide2, and VxPosSide3

```Quaternion rot = Quaternion.AngleAxis(Source.rotation.eulerAngles.y, normal) * Quaternion.FromToRotation(new Vector3(0, 1, 0), normal);
Vector3 pos = point + new Vector3(0, 0.1f, 0);
Color32 colorSideTexture = mRenderer.sharedMaterial.GetColor("_Color");

Vector3 vxPos1Side = pos + rot * (new Vector3(-1.4f, 0, -0.7f) * scale);
Vector3 vxPos2Side = pos + rot * (new Vector3(0, 0, -0.7f) * scale);
Vector3 vxPos3Side = pos + rot * (new Vector3(0, 0, 0.7f) * scale);
Vector3 vxPos4Side = pos + rot * (new Vector3(-1.4f, 0, 0.7f) * scale);

mDecalSide.SetVertex(0, vxPos1Side, colorSideTexture);
mDecalSide.SetVertex(1, vxPos2Side, colorSideTexture);
mDecalSide.SetVertex(2, vxPos3Side, colorSideTexture);
mDecalSide.SetVertex(3, vxPos4Side, colorSideTexture);```

PARTNERS