<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>inside Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/inside/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/inside/</link>
	<description></description>
	<lastBuildDate>Sun, 05 Apr 2020 03:50:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>inside Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/inside/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 1401. Circle and Rectangle Overlapping</title>
		<link>https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/</link>
					<comments>https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Sun, 05 Apr 2020 03:49:18 +0000</pubDate>
				<category><![CDATA[Geometry]]></category>
		<category><![CDATA[circle]]></category>
		<category><![CDATA[geometry]]></category>
		<category><![CDATA[inside]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[rectangle]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=6569</guid>

					<description><![CDATA[<p>Given a circle represented as (radius,&#160;x_center,&#160;y_center)&#160;and an axis-aligned rectangle represented as (x1,&#160;y1,&#160;x2,&#160;y2),&#160;where (x1,&#160;y1) are the coordinates of the bottom-left corner, and (x2,&#160;y2) are the coordinates&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/">花花酱 LeetCode 1401. Circle and Rectangle Overlapping</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Given a circle represented as (<code>radius</code>,&nbsp;<code>x_center</code>,&nbsp;<code>y_center</code>)&nbsp;and an axis-aligned rectangle represented as (<code>x1</code>,&nbsp;<code>y1</code>,&nbsp;<code>x2</code>,&nbsp;<code>y2</code>),&nbsp;where (<code>x1</code>,&nbsp;<code>y1</code>) are the coordinates of the bottom-left corner, and (<code>x2</code>,&nbsp;<code>y2</code>) are the coordinates of the top-right corner of the&nbsp;rectangle.</p>



<p>Return True if the circle and rectangle are overlapped otherwise return False.</p>



<p>In other words, check if there are&nbsp;<strong>any&nbsp;</strong>point&nbsp;(xi, yi) such that belongs to the circle and the rectangle at the same time.</p>



<p><strong>Example 1:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/02/20/sample_4_1728.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 0, y_center = 0, x1 = 1, y1 = -1, x2 = 3, y2 = 1
<strong>Output:</strong> true
<strong>Explanation:</strong> Circle and rectangle share the point (1,0) 
</pre>



<p><strong>Example 2:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/02/20/sample_2_1728.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 0, y_center = 0, x1 = -1, y1 = 0, x2 = 0, y2 = 1
<strong>Output:</strong> true
</pre>



<p><strong>Example 3:</strong></p>



<figure class="wp-block-image"><img src="https://assets.leetcode.com/uploads/2020/03/03/sample_6_1728.png" alt=""/></figure>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 1, y_center = 1, x1 = -3, y1 = -3, x2 = 3, y2 = 3
<strong>Output:</strong> true
</pre>



<p><strong>Example 4:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> radius = 1, x_center = 1, y_center = 1, x1 = 1, y1 = -3, x2 = 2, y2 = -1
<strong>Output:</strong> false
</pre>



<p><strong>Constraints:</strong></p>



<ul><li><code>1 &lt;= radius &lt;= 2000</code></li><li><code>-10^4 &lt;= x_center, y_center, x1, y1, x2, y2 &lt;= 10^4</code></li><li><code>x1 &lt; x2</code></li><li><code>y1 &lt; y2</code></li></ul>



<h2><strong>Solution: Geometry</strong></h2>



<p>Find the shortest distance from the center to the rectangle, return dist &lt;= radius.</p>



<p>Time complexity: O(1)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  bool checkOverlap(int radius, int x_center, int y_center, int x1, int y1, int x2, int y2) {
    int dx = x_center - max(x1, min(x2, x_center));
    int dy = y_center - max(y1, min(y2, y_center));
    return dx * dx + dy * dy &lt;= radius * radius;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/">花花酱 LeetCode 1401. Circle and Rectangle Overlapping</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/geometry/leetcode-1401-circle-and-rectangle-overlapping/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
