Joyce Zhou
Data Mining the City
3 min readOct 23, 2019

--

Advertisements are everywhere in the city, in the subways, on billboards and even on buildings. But how effective are they really? How often do we look up and notice a billboard?

Thesis:

Examining the effectiveness of different types of advertising around the campus.

How:

Agents walking around random points in the mapbox environment. They are each given a field of vision which allow them to observe their surroundings with peripheral vision. Once one of the advertisements hit their field of view they considered to have interacted with it.

Agent parameters include:

  • speed
  • movement limitations (such as the streets and buildings masking their view)
  • the angle of the cone of vision
walking advertisement
stationary advertisement
Left Image: current simulation | Right Image: What we couldn’t figure out
using UnityEngine;using System.Collections;using System.Collections.Generic;public class FieldOfView : MonoBehaviour{public float viewRadius;[Range(0,360)]public float viewAngle;public LayerMask targetMask;public LayerMask obstacleMask;[HideInInspector]public List<Transform> visibleTargets = new List<Transform>();public float meshResolution;public MeshFilter viewMeshFilter;Mesh viewMesh;void Start (){viewMesh = new Mesh ();viewMesh.name = "View Mesh";viewMeshFilter.mesh = viewMesh;StartCoroutine ("FindTargetWithDelay", .2f);}IEnumerator FindTargetWithDelay(float delay){while (true){yield return new WaitForSeconds(delay);FindVisibleTargets ();}}void LateUpdate(){DrawFieldOfView();}void FindVisibleTargets(){visibleTargets.Clear();Collider[] targetsInViewRadius = Physics.OverlapSphere (transform.position, viewRadius, targetMask);for (int i = 0; i < targetsInViewRadius.Length; i++){Transform target = targetsInViewRadius [i].transform;Vector3 dirToTarget = (target.position - transform.position).normalized;if (Vector3.Angle (transform.forward, dirToTarget) < viewAngle / 2){float dstToTarget = Vector3.Distance(transform.position, target.position);if (!Physics.Raycast(transform.position,dirToTarget,dstToTarget,obstacleMask)){visibleTargets.Add(target);}}}}void DrawFieldOfView (){int stepCount = Mathf.RoundToInt(viewAngle * meshResolution);float stepAngleSize = viewAngle / stepCount;List<Vector3> viewPoints = new List<Vector3>();for (int i = 0; i <= stepCount; i++){float angle = transform.eulerAngles.y - viewAngle / 2 + stepAngleSize * i;ViewCastInfo newViewCast = viewCast(angle);viewPoints.Add (newViewCast.point);}int vertexCount = viewPoints.Count + 1;Vector3[] vertices = new Vector3[vertexCount];int[] triangles = new int[(vertexCount - 2) * 3];vertices[0] = Vector3.zero;for (int i=0; i < vertexCount -1; i++){vertices[i + 1] = transform.InverseTransformPoint(viewPoints[i]);if (i < vertexCount-2){triangles[i * 3] = 0;triangles[i * 3 + 1] = i + 1;triangles[i * 3 + 2] = i + 2;}}viewMesh.Clear();viewMesh.vertices = vertices;viewMesh.triangles = triangles;viewMesh.RecalculateNormals();}ViewCastInfo viewCast(float globalAngle){Vector3 dir = DirFromAngle (globalAngle, true);RaycastHit hit;if (Physics.Raycast(transform.position, dir, out hit, viewRadius, obstacleMask)){return new ViewCastInfo(true, hit.point, hit.distance, globalAngle);} else{return new ViewCastInfo(false, transform.position + dir * viewRadius, viewRadius, globalAngle);}}public Vector3 DirFromAngle(float angleInDegrees, bool angleIsGlobal){if (!angleIsGlobal){angleInDegrees += transform.eulerAngles.y;}return new Vector3(Mathf.Sin(angleInDegrees * Mathf.Deg2Rad),0, Mathf.Cos(angleInDegrees * Mathf.Deg2Rad));}public struct ViewCastInfo{public bool hit;public Vector3 point;public float dst;public float angle;public ViewCastInfo(bool _hit, Vector3 _point, float _dst, float _angle){hit = _hit;point = _point;dst = _dst;angle = _angle;}}}

--

--