当前位置: 首页 > news >正文

android 3D球面的点,使用D3.js创建3D球面圆点环绕动画(带详细注解)

JavaScript

语言:

JaveScriptBabelCoffeeScript

确定

/**

* Create spherical spiral for given turns with almost same gap distance

* @see [Archimedean Spherical Spiral]{@link http://en.wikipedia.org/wiki/Spiral#Spherical_spiral}

* @param {number} turns - Times of turns around z-axis

* @param {number} [count=800] - Number of points on spiral

* @param {number} [radius=1] - Radius of sphere

* @returns {Point[]} - Points (r,θ,φ) of spiral in spherical coordinates

*/

function createSphericalSpiral(turns, count, radius) {

'use strict';

// Spherical coordinate system in mathematics

// (radial distance r, azimuthal angle θ, polar angle φ)

// @see [Spherical coordinate system]{@link http://en.wikipedia.org/wiki/Spherical_coordinate_system}

count = count || 800;

radius = radius || 1;

var step = 2 / count;

var phi, theta, point, points = [];

for (var i = -1; i <= 1; i += step) {

phi = Math.acos(i);

theta = 2 * turns * phi % (2 * Math.PI);

point = {

'radius': radius,

'theta': theta,

'phi': phi

};

points.push(point);

}

return points;

}

/**

* Convert from spherical coordinates (r,θ,φ) to Cartesian coordinates (x,y,z)

* @see {@link http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates}

* @param {{radius:number,theta:number,phi:number}} point - Point in spherical coordinates

* @returns {{x:number,y:number,z:number}} - Point in Cartesian coordinates

*/

function convert2xyz(point) {

'use strict';

var x = point.radius * Math.sin(point.phi) * Math.sin(point.theta);

var y = point.radius * Math.sin(point.phi) * Math.cos(point.theta);

var z = point.radius * Math.cos(point.phi);

return {

'x': x,

'y': y,

'z': z

};

}

// useage

// var spiral = createSphericalSpiral(10, 1000);

// spiralInXYZ = spiral.map(convert2xyz);

/**

* draw spherical spiral by d3 3.0

* load http://d3js.org/d3.v3.min.js first

*/

var spiral = createSphericalSpiral(10, 400);

function convert2GeoProjection(point) {

var longitude = point.theta * 180 / Math.PI;

var latitude = point.phi * 180 / Math.PI - 90;

return [longitude, latitude];

}

var width = 600,

height = 600,

speed = 0.01,

start = Date.now();

var canvas = d3.select('body').append('canvas')

.attr('width', width)

.attr('height', height);

var context = canvas.node().getContext('2d');

var projection = d3.geo.orthographic()

.scale(width / 2.2)

.clipAngle(90)

.translate([width / 2, height / 2])

.precision(0.5);

var path = d3.geo.path()

.projection(projection)

.context(context);

var sphere = {

type: 'Sphere'

};

var graticule = d3.geo.graticule();

var grid = graticule();

var spiralPositions = spiral.map(convert2GeoProjection);

var spiralLine = {

'type': 'LineString',

'coordinates': spiralPositions

};

var spiralMultiPoint = {

'type': 'MultiPoint',

'coordinates': spiralPositions

};

d3.timer(function() {

projection.rotate([speed * (Date.now() - start), -15, -10]);

context.clearRect(0, 0, width, height);

context.beginPath();

path(sphere);

context.fillStyle = '#fff';

context.fill();

context.beginPath();

path(grid);

context.lineWidth = 0.5;

context.strokeStyle = '#999';

context.stroke();

context.beginPath();

path(spiralLine);

context.lineWidth = 1.5;

context.strokeStyle = '#F00';

context.stroke();

context.beginPath();

path(spiralMultiPoint);

context.fillStyle = '#F00';

context.fill();

}, 1000);

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Java SE 6 新特性: 对脚本语言的支持
  • Java SE 6 新特性: XML API 与 Web 服务
  • 今天又要去照相
  • html5如何绑定域名,墨涩网 - Coding搭建html静态网站后绑定域名+SSL证书——墨涩网...
  • Win 2K/XP下修改网卡MAC地址的方法
  • android 模拟器应用未安装,当我在Android Studio中运行它时,Android应用程序未安装在模拟器或设备上...
  • 谈谈RJ45线序的打法及口诀
  • android 活动结束,如何在Android中完成当前活动
  • 页面导出到Excel、Word、txt
  • swift html5 相机调用,Swift调用摄像头拍照或者录制视频
  • C# 动态生成Word文档
  • 超轻量级MVC框架的设计和实现 (3)
  • html视频位置左上角,html5视频标签的Css对齐和定位
  • Java中对图片文件的类型的获取
  • html5圆环图比例教程,Chart.js 使用实例 - 圆环比例图表
  • Android 架构优化~MVP 架构改造
  • canvas绘制圆角头像
  • docker容器内的网络抓包
  • Fabric架构演变之路
  • HTTP传输编码增加了传输量,只为解决这一个问题 | 实用 HTTP
  • JavaScript创建对象的四种方式
  • PHP CLI应用的调试原理
  • python学习笔记-类对象的信息
  • Redux 中间件分析
  • 从@property说起(二)当我们写下@property (nonatomic, weak) id obj时,我们究竟写了什么...
  • 从地狱到天堂,Node 回调向 async/await 转变
  • 动手做个聊天室,前端工程师百无聊赖的人生
  • 翻译 | 老司机带你秒懂内存管理 - 第一部(共三部)
  • 排序(1):冒泡排序
  • 嵌入式文件系统
  • 腾讯优测优分享 | 你是否体验过Android手机插入耳机后仍外放的尴尬?
  • 突破自己的技术思维
  • 在Mac OS X上安装 Ruby运行环境
  • kubernetes资源对象--ingress
  • mysql面试题分组并合并列
  • Spark2.4.0源码分析之WorldCount 默认shuffling并行度为200(九) ...
  • 选择阿里云数据库HBase版十大理由
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • (LeetCode) T14. Longest Common Prefix
  • (LLM) 很笨
  • (Matalb分类预测)GA-BP遗传算法优化BP神经网络的多维分类预测
  • (附源码)springboot“微印象”在线打印预约系统 毕业设计 061642
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (附源码)ssm经济信息门户网站 毕业设计 141634
  • (每日一问)基础知识:堆与栈的区别
  • (十八)SpringBoot之发送QQ邮件
  • (贪心) LeetCode 45. 跳跃游戏 II
  • (推荐)叮当——中文语音对话机器人
  • (转)编辑寄语:因为爱心,所以美丽
  • .[backups@airmail.cc].faust勒索病毒的最新威胁:如何恢复您的数据?
  • .bat批处理(三):变量声明、设置、拼接、截取
  • .Net 6.0 处理跨域的方式
  • .NET 动态调用WebService + WSE + UsernameToken
  • .NET建议使用的大小写命名原则
  • .Net面试题4